使用vue去请求接口发现问题来了:使用vue去请求接口发现问题来了:我请求只能请求一次,然后在按按钮去请求的时候发现502(这个是接口定义的)502就是传了空的值过来 这个是其中一种情况,还有别的情况 你看了 大可试试我这样的办法然后发现我前端代码没有问题,接口代码也没有问题
data() {

return {

form: {

old_password: '',

new_password: '',

confirm_password: ''

}

}
},
data() {

return {

form: {

old_password: '',

new_password: '',

confirm_password: ''

}

}
},就是把值在重新赋值回去就可以解决了
this.$http.post('/api/users/modifyPassword', this.form,

(res) => {

this.form = {

old_password: this.form.old_password,

new_password: this.form.new_password,

confirm_password: this.form.confirm_password

}

if (is.object(res)) {

console.log(res)

if (res.code === '0') {

this.$router.push({ path: '/my/' })

this.$toast.show(res.msg)

} else {

this.$toast.show(res.msg)

}

}

})

this.$http.post('/api/users/modifyPassword', this.form,

(res) => {

this.form = {

old_password: this.form.old_password,

new_password: this.form.new_password,

confirm_password: this.form.confirm_password

}

if (is.object(res)) {

console.log(res)

if (res.code === '0') {

this.$router.push({ path: '/my/' })

this.$toast.show(res.msg)

} else {

this.$toast.show(res.msg)

}

}

})
补充知识:vue中使用axios请求接口,请求会发送两次补充知识:补充知识:vue中使用axios请求接口,请求会发送两次vue中使用axios请求接口,请求会发送两次的问题浏览器分为简单请求以及非简单请求:解决方案:解决方案:解决方案:跨域请求需要先发一次Option预请求,OPTIONS是检验是否允许跨域的,如果不希望OPTIONS请求, 直接让后端遇到option直接返回就可以了,前端可不做处理。以上这篇解决vue请求接口第一次成功,第二次失败问题就是小编分享给大家的全部内容了,希望能给大家一个参考。