Error (warning message)
Solution
Add context: this in the pop-up box
Dialog.alert({
context: this,//不添加这个会报如上错误
title: '标题',
message: '弹窗内容'
}).then(() => {
// on close
});
The full page is as follows
Front end wxml page
<van-dialog id="van-dialog"/>
js page
import Dialog from '@vant/weapp/dialog/dialog';
Component({
/**
* 组件的属性列表
*/
properties: {
},
/**
* 组件的初始数据
*/
data: {
},
/**
* 组件的方法列表
*/
methods: {
},
lifetimes: {
attached: function() {
console.log('在组件实例进入页面节点树时执行')
Dialog.alert({
context: this,//不添加这个会报如上错误
title: '标题',
message: '弹窗内容'
}).then(() => {
// on close
});
},
detached: function() {
console.log('在组件实例被从页面节点树移除时执行')
},
},
})
json page
{
"component": true,
"usingComponents": {
"van-dialog": "@vant/weapp/dialog/index"
}
}