美文网首页
switch 的使用

switch 的使用

作者: 稻草人_9ac7 | 来源:发表于2019-12-18 11:25 被阅读0次

<template>
  <div>测试
<mt-switch v-model="value" @change="swfn"></mt-switch>
{{value}}

  </div>
</template>
<script>
export default {
  data() {
    return {
      value:true
    }
  },
  methods: {  
   swfn(e){    
    if(e){
      console.log("开",e)
    }
    else{
      console.log("关",e)
    }
   }

  },
}
</script>
<style scoped>

</style>

分析:
1)使用v-model来绑定,如果使用官网的:value.sync="value"不会起作用;
2)change事件可以监听到switc的变化,change的回调参数就是switch的布尔值;
3)change的回调参数是和绑定的value相关的,不需要赋值就可以直接使用。
就是不需要this.value=e;便可以使用value

相关文章

网友评论

      本文标题:switch 的使用

      本文链接:https://www.haomeiwen.com/subject/chnynctx.html