Vant/Weapp/Dialog/before-close asyncClose 异步关闭的用法
Vant/Weapp/Dialog/before-close的用法_zszcc的博客-CSDN博客before-close用法应该是放在data里面使用并且是异步的但是verify的方法里是无法访问到this的,你学需要在onload生命周期函数里去绑定this...个人建议还是自定义 取消 确定按钮吧/* 自定义确认取消按钮就是了...........*///关掉自带确认按钮showConfir
Vant/Weapp/Dialog/before-close的用法_zszcc的博客-CSDN博客
before-close用法应该是放在data里面使用并且是异步的但是verify的方法里是无法访问到this的,你需要在onload生命周期函数里去绑定this
如果想要在beforeClose获取data中某个属性,是不能用this.data获取data中的数据,这样是获取不到数据的
可以通过微信小程序——getCurrentPages(获取当前页面栈)来获取data
const pages = getCurrentPages()
let page = pages[pages.length-1]
page就是当前页面
此时就可以用page.data来获取当前页面的属性
//也可以一开始就在onload绑定this到异步方法
onLoad() {
this.setData({
verify: this.data.verify.bind(this),
})
}
...个人建议还是自定义 取消 确定按钮吧
/* 自定义确认取消按钮就是了...........*/
//关掉自带确认按钮
showConfirmButton="{{false}}"
<view class="flex">
<button bindtap="showCxyFn" >取消</button>
<button type="warn" bindtap="SaveCxyFn" >保存</button>
</view>
/*
报错内容:
WAServiceMainContext.js:2 TypeError: beforeClose is not a function
at Li.handleAction (index.js? [sm]:116)
at Li.onConfirm (index.js? [sm]:76)
代码逻辑:
*/
handleAction: function (action) {
var _a;
var _this = this;
this.$emit(action, { dialog: this });
var _b = this.data, asyncClose = _b.asyncClose, beforeClose = _b.beforeClose;
//关键在这里
//beforeClose 来自 _b 来自 this.data
if (!asyncClose && !beforeClose) {
this.close(action);
return;
}
this.setData((_a = {},
_a["loading." + action] = true,
_a));
if (beforeClose) {
//报错在这里调用beforeClose
(0, utils_1.toPromise)(beforeClose(action)).then(function (value) {
if (value) {
_this.close(action);
}
else {
_this.stopLoading();
}
});
}
},
/*--------------------*/
更多推荐
所有评论(0)