踩坑分享( 8 )- Vue使用this.$alert()报错:Uncaught (in promise) TypeError: this.$alert is not a function a
Vue使用this.$alert()报错:Uncaught (in promise) TypeError: this.$alert is not a function a
·
代码
axios.post("/order", orderDto).then(function (res) { if (res.data.code == 1) { this.$alert(res.data.data, '下单成功!', { confirmButtonText: '点击返回首页', }).then(function () { window.location.href = '/QSG.html'; }); } else { this_vue.$message.error(res.data.data); } })
报错
在百度查了半天不知道什么原因,vue是有这个方法的。突然一下想到了,this在axios.post().then()里面使用代表是window对象不是vue,而window是没有$alert的。
在axios请求外面添加一个 this_vue=this。用来代表vue对象。
这样就成功了。
更多推荐
已为社区贡献5条内容
所有评论(0)