为了账号安全,请及时绑定邮箱和手机立即绑定

无法使用 vue.js 发布

无法使用 vue.js 发布

慕姐4208626 2023-02-17 17:21:17
我想使用“vue-resource”发布表单数据,但出现错误。我用 vue-cli 和 vuetify 编写了代码。错误[Vue 警告]:v-on 处理程序中的错误:“TypeError:this.$http.post(...).error 不是函数”应用程序.vue<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> 我尝试在 main.js 中写“import VueResource from 'vue-resource'”,但是没有效果。我该如何解决?
查看完整描述

1 回答

?
哈士奇WWW

TA贡献1799条经验 获得超6个赞

尝试使用axios或fetch


// install axios first


import axios from 'axios'


// ... some code here


axios.post(url, data).then(response => {}).catch(error => {})



// or you can use fetch


let response = await fetch(url, { method:'POST', headers: {'Content-Type': 'application/json;charset=utf-8'}, body: JSON.stringify(data) })


// getting result

let json = await response.json()


查看完整回答
反对 回复 2023-02-17
  • 1 回答
  • 0 关注
  • 116 浏览
慕课专栏
更多

添加回答

举报

0/150
提交
取消
微信客服

购课补贴
联系客服咨询优惠详情

帮助反馈 APP下载

慕课网APP
您的移动学习伙伴

公众号

扫描二维码
关注慕课网微信公众号