代码

                    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对象。

这样就成功了。

Logo

前往低代码交流专区

更多推荐