<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>