简单描述一下功能,活动开启的switch,在点击关闭时弹出是否停止活动的model层,点击确定停止活动关闭,点击取消switch状态依然是开启。
主要用this.$set 去更新视图层switch的状态
下面附上完整demo
<template>
<view>
<view class="">
<switch :checked="hadOpen.checked" color="#4dd765" @change="switchChange"/>
<text>{{opentext}}</text>
</view>
</view>
</template>
<script>
export default {
data() {
return {
hadOpen: { checked: true },
opentext: "开启",
}
},
methods: {
switchChange: function (e) {
let value = e.target.value
let that = this
this.$set(this.hadOpen, 'checked', value)
if (value) {
that.opentext = "开启";
}else{
that.opentext = "开启";
uni.showModal({
content: '您确定立即停止活动?',
confirmText: "取消",
cancelText: "确定停止",
confirmColor:'#cbcbcb',
cancelColor:'#0fd068',
success: function (res) {
if (res.confirm) {
that.$set(that.hadOpen, 'checked', true)
that.opentext = "开启";
} else if (res.cancel) {
that.opentext = "停止";
}
}
});
}
},
}
}
</script>
<style>
</style>