天天看点

vue请求接口第一次成功,第二次失败

使用vue去请求接口发现问题来了:

我请求只能请求一次,然后在按按钮去请求的时候发现

502(这个是接口定义的)502就是传了空的值过来 这个是其中一种情况,还有别的情况 你看了 大可试试我这样的办法

然后发现我前端代码没有问题,接口代码也没有问题

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)
            }
        }
    })