码迷,mamicode.com
首页 > 其他好文 > 详细

自定义 vue switch 组件

时间:2018-12-29 01:04:22      阅读:959      评论:0      收藏:0      [点我收藏+]

标签:hid   定义   default   eth   isp   lan   lang   引用   overflow   

 1 <template>
 2   <div class="switch clearfix"
 3     @click="toggle"
 4     v-bind:style="{ background: activeState ? activeColor : inActiveColor }">
 5     <div v-show="activeState" class="switch-text switch-on"
 6       transition="switchOn">{{activeText}}</div>
 7     <div class="switch-icon"></div>
 8     <div v-show="!activeState" class="switch-text switch-off">{{inActiveText}}</div>
 9   </div>
10 </template>
11 
12 <script>
13 export default {
14   props: {
15     active: {
16       Type: Boolean,
17       default: false
18     },
19     activeText: {
20       Type: String,
21       default: ‘onssssss‘
22     },
23     activeColor: {
24       Type: String,
25       default: ‘#c532a3‘
26     },
27     inActiveText: {
28       Type: String,
29       default: ‘off‘
30     },
31     inActiveColor: {
32       Type: String,
33       default: ‘yellow‘
34     }
35   },
36   data () {
37     return {
38       activeState: this.active
39     }
40   },
41   methods: {
42     toggle () {
43       this.activeState = !this.activeState
44     }
45   }
46 }
47 </script>
48 
49 <style lang="scss" scoped>
50 .switch{
51   display: inline-block;
52   border-radius: 15px;
53   box-sizing: border-box;
54   overflow: hidden;
55   & > div{
56     float: left;
57   }
58   .switch-text{
59     height: 28px;
60     line-height: 28px;
61     color: #ffffff;
62     font-size: 14px;
63     padding: 0 8px;
64   }
65   .switch-icon{
66     width: 26px;
67     height: 26px;
68     border-radius: 13px;
69     background-color: #ffffff;
70     border-radius: 1px solid #dcdcdc;
71     margin: 1px;
72   }
73 }
74 </style>

代码如上,引用自己引用下

自定义 vue switch 组件

标签:hid   定义   default   eth   isp   lan   lang   引用   overflow   

原文地址:https://www.cnblogs.com/fengyingYZ/p/10193466.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!