Javascript Can';t使用vue.js发布
我想使用“vue资源”发布表单数据,但出现错误。 我使用vue cli和vuetify编写了代码 错误 [Vue warn]:v-on处理程序中的错误:“TypeError:this.$http.post(…)。错误不是函数” App.vueJavascript Can';t使用vue.js发布,javascript,vue.js,vuetify.js,vue-resource,Javascript,Vue.js,Vuetify.js,Vue Resource,我想使用“vue资源”发布表单数据,但出现错误。 我使用vue cli和vuetify编写了代码 错误 [Vue warn]:v-on处理程序中的错误:“TypeError:this.$http.post(…)。错误不是函数” App.vue <template> <v-app> <v-main> <v-container class="px-0"> <v-form ref=&quo
<template>
<v-app>
<v-main>
<v-container class="px-0">
<v-form ref="form" @submit="addEvent">
<p class="text-uppercase">Question?</p>
<v-radio-group v-model="newEvent.select1" row>
<v-radio label="aaa" value="aaa"></v-radio>
<v-radio label="bbb" value="bbb"></v-radio>
</v-radio-group>
<input type="submit" depressed color="primary" value="OK!">
</v-form>
</v-container>
</v-main>
</v-app>
</template>
<script>
export default {
name: 'App',
data () {
return {
users: [],
newEvent: {
select1: '',
}
}
},
methods: {
addEvent: function (e) {
e.preventDefault()
if (this.isValid) {
console.log("success")
console.log("select1: " + this.newEvent.select1)
this.$http.post('URL..', this.newEvent, function (data, status, request) {
console.log("post success")
console.log(status)
}).error(function (data, status, request) {
console.log("post failed")
})
}else{
console.log("need edit")
}
},
},
computed: {
isValid: function () {
var valid = true
for (var key in this.data) {
if (!this.data[key]) {
valid = false
}
}
return valid
}
},
};
</script>
问题是什么
导出默认值{
名称:“应用程序”,
数据(){
返回{
用户:[],
新事件:{
选择1:“”,
}
}
},
方法:{
附录:功能(e){
e、 预防默认值()
如果(this.isValid){
console.log(“成功”)
console.log(“select1:+this.newEvent.select1)
this.$http.post('URL..',this.newEvent,函数(数据、状态、请求){
console.log(“成功后”)
console.log(状态)
}).错误(功能(数据、状态、请求){
console.log(“post失败”)
})
}否则{
console.log(“需要编辑”)
}
},
},
计算:{
isValid:函数(){
var valid=true
for(此.data中的var键){
如果(!this.data[key]){
有效=错误
}
}
返回有效
}
},
};
我尝试在main.js中编写“从“vue-resource”导入VueResource”,但没有效果
如何解决此问题?尝试使用
axios
或fetch
//首先安装axios
从“axios”导入axios
// ... 这里有一些代码
post(url,data).then(response=>{}).catch(error=>{})
//或者您可以使用fetch
let response=wait-fetch(url,{method:'POST',headers:{'Content-Type':'application/json;charset=utf-8'},body:json.stringify(data)})
//取得成果
让json=wait response.json()