页面报错
Uncaught TypeError: Cannot read property 'alert' of undefined
使用this在方法中无法定向到参数,所以使用let that = this 重定向
let that = this
$.post('url', {
type: '参数'
}, function (res) {
that.$dialog.alert({
title: "标题", //加上标题
message: "内容", //改变弹出框的内容
showCancelButton: true //展示取消按钮
})
.then(() => { //点击确认按钮后的调用
console.log("点击了确认按钮噢")
})
.catch(() => { //点击取消按钮后的调用
console.log("点击了取消按钮噢")
})
}, 'json')
博主发现重定向问题是因为使用vue是function 导致,优化后代码如下:
$.post('url', {
type: '参数'
}, (res)=> {
vant.Dialog.alert({
title: "标题", //加上标题
message: "内容", //改变弹出框的内容
showCancelButton: true //展示取消按钮
})
.then(() => { //点击确认按钮后的调用
console.log("点击了确认按钮噢")
})
.catch(() => { //点击取消按钮后的调用
console.log("点击了取消按钮噢")
})
}, 'json')
只需要将***function()更改为()=>***即可。其他方法内同理