uni-app點擊按鈕彈出提示框-uni.showModal(OBJECT),選擇確定和取消

參考文檔:
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>

效果:點擊按鈕的時候,
會彈出一個提示框


?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點,簡書系信息發(fā)布平臺,僅提供信息存儲服務(wù)。

推薦閱讀更多精彩內(nèi)容