## Wrong
//index.wxml
<van-dialog
use-slot
title="title"
show="{{ showDialog }}"
beforeClose="beforeClose">
<view class="dialog-content"></view>
</van-dialog>
//index.js
page({
data:{
showDialog:true
},
beforeClose() {
return new Promise((resolve) => {
setTimeout(() => {
if (action === 'confirm') {
resolve(true);
} else {
resolve(false);
}
}, 1000);
});
})
},
## Right
//index.wxml
<van-dialog
use-slot
title="title"
show="{{ showDialog }}"
before-close="{{ beforeClose }}">
<view class="dialog-content">
</view>
</van-dialog>
//index.js
Page({
data: {
showDialog:true,
beforeClose(action) {
return new Promise((resolve) => {
setTimeout(() => {
if (action === 'confirm') {
resolve(true);
} else {
resolve(false);
}
}, 1000);
});
},
}
})
If you want to get a property in data beforeClose, you can't use this.data to get the data in data, so you can't get the data
You can get the data through the WeChat applet - getCurrentPages (get the current page stack)
const pages = getCurrentPages()
let page = pages[pages.length-1]
page is the current page
At this point you can use page.data to get the properties of the current page
Read More:
- The toast light prompt of vant in Vue reports an error
- Element El dialog close callback error [How to Solve]
- [Solved] Vant quoted lazload error: Failed to Resolve directive: lazy
- [Solved] vant-weapp ui SwipeCell Error: Ignored attempt to cancel a touchmove event with cancelable=false…
- [Solved] Uniapp project use vant icon Error: (module build failed from./node_modules/postcss loader/SRC/index)
- How to Solve Vue cli syntax Close Error
- Vue3.0 Use el-dialog visible Error: ‘.sync‘ modifier on ‘v-bind‘ directive is deprecated. Use ‘v-model:pro
- [Solved] Vue3.0 Error: The component has been registered but not used vue/no-unused-components, Close eslint
- Error in created hook: “SyntaxError: Unexpected token u in JSON at position 0
- How to solve Uncaught (in promise) error in VUE?
- [Solved] AES encryption in ie11 results in an error (missing ‘)‘
- uniapp [Vue warn]: Error in onLoad hook: “TypeError: Attempting to change the setter of an unconfigu
- Using for in loop complex data types (object and array) in ES6
- How to Solve Uncaught (in promise) Error (Two Solutions)
- [Solved] Vue3 Error: Cannot use ‘in‘ operator to search for ‘path‘ in undefined
- The addition, deletion and modification of DOM in JS Foundation
- [Solved] Error in created hook: “SyntaxError: Unexpected token o in JSON at position 1“
- Vue: How to Fix “not displaying the holder in IE9 and below”
- Module not found: Error: Can‘t resolve ‘core-js/modules/es.promise.js‘ in
- [Solved] Binding onclick event in JS: for loop: error uncaught typeerror: cannot set properties of undefined (setting ‘classname’)