首页 >> js开发 >> js解决vue请求接口第一次成功,第二次失败问题js大全
js解决vue请求接口第一次成功,第二次失败问题js大全
发布时间: 2021年1月13日 | 浏览:
| 分类:js开发
使用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请求接口第一次成功,第二次失败问题就是小编分享给大家的全部内容了,希望能给大家一个参考。
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请求接口第一次成功,第二次失败问题就是小编分享给大家的全部内容了,希望能给大家一个参考。
相关文章:
- jsVue 解决在element中使用$notify在提示信息中换行问题js大全
- js在vue中使用image-webpack-loader实例js大全
- js解决vant的Toast组件时提示not defined的问题js大全
- jsvue实现动态给id赋值,点击事件获取当前点击的元素的id操作js大全
- jsJs数组扁平化实现方法代码总汇js大全
- jsvue 实现element-ui中的加载中状态js大全
- jsVue 401配合Vuex防止多次弹框的案例js大全
- jsvue router返回到指定的路由的场景分析js大全
- jsVue 防止短时间内连续点击后多次触发请求的操作js大全
- jsvue mvvm数据响应实现js大全