參考文檔:
https://uniapp.dcloud.io/api/ui/prompt?id=showmodal
顯示模態(tài)彈窗,可以只有一個確定按鈕,也可以同時有確定和取消按鈕。類似于一個API整合了 html 中:alert、confirm。
uni.showModal({
title: '提示',
content: '這是一個模態(tài)彈窗',
success: function (res) {
if (res.confirm) {
console.log('用戶點擊確定');
} else if (res.cancel) {
console.log('用戶點擊取消');
}
}
});
test.vue
<template>
<button @click.stop="isLeave()">離廠解綁</button>
</template>
<script>
export default {
data() {
return {};
},
onLoad() {},
methods: {
isLeave(id) {
uni.showModal({
title: '提示',
content: '這是一個模態(tài)彈窗',
success: function(res) {
if (res.confirm) {
console.log('用戶點擊確定');
} else if (res.cancel) {
console.log('用戶點擊取消');
}
}
});
},
},
}
</script>
<style>
</style>
效果:點擊按鈕的時候,
會彈出一個提示框