admin管理员组文章数量:1323348
I'm trying to post some data to a fake API which in this case is jsonPlaceHolder and the idea is that the user can enter a title and content and post it to this API at using axios by pressing a button but i keep getting the error in the title of this question.
here is the code:
<template>
<div>
<h1>it 2020 people</h1>
<p>type in your title</p>
<input type="text" v-model="title" />
<p>type your content</p>
<textarea cols="30" rows="1" v-model="body"></textarea>
<h3>your title is {{ title }}</h3>
<h3>your content is {{ body }}</h3>
<button v-on:click="post()">post</button>
</div>
</template>
<script>
import Vue from "vue";
import Axios from "axios";
Vue.use(Axios);
export default {
ponents: {},
data() {
return {
title: "",
body: "",
};
},
methods: {
post: function () {
Vue.axios
.post(";, {
title: this.title,
body: this.body,
userid: 1,
})
.then(function (data) {
return console.log(data);
});
},
},
};
and this is the error that appears before running anything:
Uncaught (in promise) TypeError: Cannot read property 'protocol' of undefined
at isURLSameOrigin (isURLSameOrigin.js?3934:57)
at dispatchXhrRequest (xhr.js?b50d:115)
at new Promise (<anonymous>)
at xhrAdapter (xhr.js?b50d:13)
at dispatchRequest (dispatchRequest.js?5270:52)
isURLSameOrigin @ isURLSameOrigin.js?3934:57
dispatchXhrRequest @ xhr.js?b50d:115
xhrAdapter @ xhr.js?b50d:13
dispatchRequest @ dispatchRequest.js?5270:52
and this is the error i get after pressing the button that is supposed to send the data to the API:
[Vue warn]: Error in v-on handler: "TypeError: vue__WEBPACK_IMPORTED_MODULE_0__.default.axios is not a function"
found in
---> <App> at src/App.vue
<Root>
warn @ vue.runtime.esm.js?2b0e:619
logError @ vue.runtime.esm.js?2b0e:1884
globalHandleError @ vue.runtime.esm.js?2b0e:1879
handleError @ vue.runtime.esm.js?2b0e:1839
invokeWithErrorHandling @ vue.runtime.esm.js?2b0e:1862
invoker @ vue.runtime.esm.js?2b0e:2179
original._wrapper @ vue.runtime.esm.js?2b0e:6917
I really don't have any clue what is the problem, any helpful information is much appreciated. thanks in advance.
I'm trying to post some data to a fake API which in this case is jsonPlaceHolder and the idea is that the user can enter a title and content and post it to this API at https://jsonplaceholder.typicode./posts using axios by pressing a button but i keep getting the error in the title of this question.
here is the code:
<template>
<div>
<h1>it 2020 people</h1>
<p>type in your title</p>
<input type="text" v-model="title" />
<p>type your content</p>
<textarea cols="30" rows="1" v-model="body"></textarea>
<h3>your title is {{ title }}</h3>
<h3>your content is {{ body }}</h3>
<button v-on:click="post()">post</button>
</div>
</template>
<script>
import Vue from "vue";
import Axios from "axios";
Vue.use(Axios);
export default {
ponents: {},
data() {
return {
title: "",
body: "",
};
},
methods: {
post: function () {
Vue.axios
.post("https://jsonplaceholder.typicode./posts", {
title: this.title,
body: this.body,
userid: 1,
})
.then(function (data) {
return console.log(data);
});
},
},
};
and this is the error that appears before running anything:
Uncaught (in promise) TypeError: Cannot read property 'protocol' of undefined
at isURLSameOrigin (isURLSameOrigin.js?3934:57)
at dispatchXhrRequest (xhr.js?b50d:115)
at new Promise (<anonymous>)
at xhrAdapter (xhr.js?b50d:13)
at dispatchRequest (dispatchRequest.js?5270:52)
isURLSameOrigin @ isURLSameOrigin.js?3934:57
dispatchXhrRequest @ xhr.js?b50d:115
xhrAdapter @ xhr.js?b50d:13
dispatchRequest @ dispatchRequest.js?5270:52
and this is the error i get after pressing the button that is supposed to send the data to the API:
[Vue warn]: Error in v-on handler: "TypeError: vue__WEBPACK_IMPORTED_MODULE_0__.default.axios is not a function"
found in
---> <App> at src/App.vue
<Root>
warn @ vue.runtime.esm.js?2b0e:619
logError @ vue.runtime.esm.js?2b0e:1884
globalHandleError @ vue.runtime.esm.js?2b0e:1879
handleError @ vue.runtime.esm.js?2b0e:1839
invokeWithErrorHandling @ vue.runtime.esm.js?2b0e:1862
invoker @ vue.runtime.esm.js?2b0e:2179
original._wrapper @ vue.runtime.esm.js?2b0e:6917
I really don't have any clue what is the problem, any helpful information is much appreciated. thanks in advance.
Share Improve this question edited Oct 7, 2020 at 16:56 Daniel Widdis 9,14013 gold badges48 silver badges68 bronze badges asked Oct 7, 2020 at 1:30 MiladMilad 771 gold badge2 silver badges7 bronze badges 8-
Vue.use(Axios);
版权声明:本文标题:javascript - Uncaught (in promise) TypeError: Cannot read property 'protocol' of undefined - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1742131771a2422192.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论