uni.showModal如何获取data里面的参数
时间: 2023-10-25 13:26:30 浏览: 75
浅析微信小程序modal弹窗关闭默认会执行cancel问题
要在uni.showModal函数中获取data里面的参数,可以使用bind方法来确保函数内部的this指向正确。首先在函数外部声明一个变量that,将this赋值给它。然后在success回调函数中通过that来访问data里的数据。例如,在uni.showModal函数中可以这样写:
var that = this;
uni.showModal({
title: '提示',
content: '这是一个模态弹窗',
success: function(res) {
if (res.confirm) {
console.log('用户点击确定');
console.log(that.data.parameter); //
} else if (res.cancel) {
console.log('用户点击取消');
console.log(that.data.parameter); //
}
}.bind(that) //
});
这样就可以通过that来访问data里的参数了。请注意,在success回调函数后面加上bind(that)来确保函数内部的this指向正确。同时,可以使用that.data.parameter来获取data里的参数。<span class="em">1</span><span class="em">2</span><span class="em">3</span>
#### 引用[.reference_title]
- *1* *2* [uni.showModal 里的this指向](https://blog.csdn.net/weixin_45723025/article/details/125971765)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_1"}}] [.reference_item style="max-width: 50%"]
- *3* [uni.showModal使用](https://blog.csdn.net/qq_37570945/article/details/121380705)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_1"}}] [.reference_item style="max-width: 50%"]
[ .reference_list ]
阅读全文