使用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) } } })
本文介绍了一个Vue应用中遇到的问题:接口只能被成功请求一次。文章详细解释了问题出现的原因,并提供了一种解决方案——通过将表单值重新赋值来避免请求失败。
4万+

被折叠的 条评论
为什么被折叠?



