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