名称 | 类型 | 默认值 | 必填 | 描述 |
checked | boolean | false | 否 | 是否选中。 |
名称 | 参数 | 描述 | 名称 | 参数 |
change | { checked: checkedValue } | 选中状态改变时触发该事件。 | change | { checked: checkedValue } |
<div class="container"> <switch showtext="true" texton="开启" textoff="关闭" checked="true" @change="switchChange"> </switch> <div class="top" show="{{top}}"> <text>开启状态</text> </div> <div class="top2" show="{{top2}}"> <text>关闭状态</text> </div> </div> |
.container { flex-direction: column; justify-content: center; align-items: center; } switch{ texton-color:#002aff; textoff-color:silver; text-padding:30px; } .top{ flex-direction: column; justify-content: center; align-items: center; width: 200px; height: 200px; background-color: cadetblue; } .top2{ flex-direction: column; justify-content: center; align-items: center; width: 200px; height: 200px; background-color: darkorchid; } |
import prompt from '@system.prompt'; export default { data: { title: 'World', top: true, top2: false }, switchChange(e){ console.log(e.checked); if(e.checked){ this.top = true this.top2 = false prompt.showToast({ message: "打开开关" }); }else{ this.top = false this.top2 = true prompt.showToast({ message: "关闭开关" }); } } } |