uni-app switch先彈窗提示再改變其狀態值


<template>  
    <view class="content">  
        <switch :checked="isChecked" @change="switchchange"></switch>  
    </view>  
</template>
<script>  
    export default {  
        data() {  
            return {  
                isChecked: false  
            }  
        },  
        onLoad() {},  
        methods: {  
            switchchange(e) {  
                // TODO H5端內置組件實現的有問題,使用v-model無效,先這樣解決  
				let flag = e.detail.value;
                this.isChecked = !this.isChecked;  
				
                setTimeout( () => {  
		    uni.showModal({
			title: '開關',
			content: '確定要執行此操作嗎?',
			success:(res) => {
				if (res.confirm) {
					flag ? this.isChecked = true : this.isChecked = false;
				     console.log('用戶點擊確定');
				} else if (res.cancel) {
					this.isChecked = !this.isChecked;
					console.log('用戶點擊取消');
				}
			}
		    })
                }, 100);
            }  
        }  
    }  
</script>

<style lang="less">
	page {
		background: #f8f8f8;
	}
</style>

  


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM