如何调用这个函数uni.$isSure = function(content) { uni.showModal({ title: '提示', content: content, confirmText: '取消', cancelText: '确认', success: function(res) { if (res.confirm) { console.log('用户点击取消') } else if (res.cancel) { console.log('执行指定的函数') } } }) } 让它执行指定的函数
时间: 2024-04-12 19:29:59 浏览: 113
你可以按照以下步骤来调用这个函数并执行指定的函数:
1. 在你的代码中引入该函数,确保它在需要调用的地方可以被访问到。
2. 在你想要执行指定函数的地方,调用 `uni.$isSure` 函数,并将要显示的提示内容作为参数传入。
3. 在 `success` 回调函数中,根据用户的选择来执行指定的函数。如果用户点击了取消按钮,则执行指定的函数。
以下是一个示例代码:
```javascript
// 引入函数
uni.$isSure = function(content) {
uni.showModal({
title: '提示',
content: content,
confirmText: '取消',
cancelText: '确认',
success: function(res) {
if (res.confirm) {
console.log('用户点击取消');
} else if (res.cancel) {
// 执行指定的函数
console.log('执行指定的函数');
// 在这里调用你想执行的函数
}
}
});
};
// 在需要调用的地方调用函数并传入提示内容和指定函数
uni.$isSure('确认执行指定的函数吗?');
```
在 `success` 回调函数中的 `else if (res.cancel)` 部分,你可以替换成你所需执行的函数或者函数调用。
相关问题
onDetailTap(item) { uni.setStorageSync("useridTag",this.userid); this.$utils.jump(`./detail?id=${item.id}&userid=`+this.userid) }, // 修改 onUpdateTap(id){ uni.setStorageSync("useridTag",this.userid); this.$utils.jump(`./add-or-update?id=${id}`) }, // 添加 onAddTap(){ uni.setStorageSync("useridTag",this.userid); this.$utils.jump(`./add-or-update`) }, onDeleteTap(id){ var _this = this; uni.showModal({ title: '提示', content: '是否确认删除', success: async function(res) { if (res.confirm) { await _this.$api.del('baodaoxinxi', JSON.stringify([id])); _this.hasNext = true // 重置分页参数页数为1 _this.mescroll.resetUpScroll() } } }); }, // 搜索 async search(){ this.mescroll.num = 1 let searchForm = { page: this.mescroll.num, limit: this.mescroll.size } if(this.searchForm.xingming){ searchForm['xingming'] = '%' + this.searchForm.xingming + '%' } if(this.searchForm.baodaozhuanye){ searchForm['baodaozhuanye'] = '%' + this.searchForm.baodaozhuanye + '%' } let res = {}; if(this.userid) { res = await this.$api.page(`baodaoxinxi`, searchForm); } else { res = await this.$api.list(`baodaoxinxi`, searchForm); } // 如果是第一页数据置空 if (this.mescroll.num == 1) this.list = []; this.list = this.list.concat(res.data.list); if (res.data.list.length == 0) this.hasNext = false; this.mescroll.endSuccess(this.mescroll.size, this.hasNext); } } };
这段代码是一个Vue组件中的一个methods对象,具有以下几个方法:
1. onDetailTap(item): 点击“详情”按钮时触发,将item对象中的id值和当前用户的userid保存到本地存储中,然后跳转到“detail”页面。
2. onUpdateTap(id): 点击“修改”按钮时触发,将id值保存到本地存储中,然后跳转到“add-or-update”页面。
3. onAddTap(): 点击“添加”按钮时触发,跳转到“add-or-update”页面。
4. onDeleteTap(id): 点击“删除”按钮时触发,弹出确认对话框,如果用户确认删除,则调用后端API进行删除操作,并重新加载当前页面数据。
5. search(): 点击“搜索”按钮时触发,根据用户输入的搜索条件发送请求到后端API,并重新加载当前页面数据。
这些方法主要是用来实现页面上的各种交互操作,包括跳转页面、发送请求、删除数据等。其中涉及到了本地存储、异步请求、条件搜索等方面的知识,需要结合具体的业务场景来理解。
解释一下这段代码 onLoad(option) { //可否对onload方法做简单说明 let titleChn = '水费缴费' if(option.type === 'sf'){ titleChn = '水费缴费' } if(option.type === 'df'){ titleChn = '电费缴费' } if(option.type === 'rq'){ titleChn = '燃气缴费' } this.payTitle = titleChn }, methods:{ showHelp(){ uni.showModal({ title:'如何查户号?', content:'您可以查看缴费账单、催缴短信,或拨打机构客服电话查询。', showCancel:false, confirmColor:'#67cc8c', confirmText:'确定' }) }, gotoPayment(typeCode){ uni.navigateTo({
这段代码是一个小程序页面的 onLoad 方法,当页面加载时会执行该方法。其中,通过 option 参数来判断缴费类型(水费、电费、燃气费),并将中文标题赋值给变量 titleChn。最后将 titleChn 赋值给该页面的 payTitle 变量。
在 methods 中,定义了两个方法:showHelp 和 gotoPayment。showHelp 方法会弹出一个模态框,显示如何查找户号的提示信息。gotoPayment 方法则是跳转到缴费页面,传递参数 typeCode 表示缴费类型。具体跳转路径和参数需要根据实际需求进行修改。
阅读全文
相关推荐
















