File tree 1 file changed +47
-36
lines changed
1 file changed +47
-36
lines changed Original file line number Diff line number Diff line change 1
1
<template >
2
- <button @click =" toggle" :class =" {checked:value}" > <span ></span > </button >
2
+ <button @click =" toggle" :class =" {checked:value}" ><span ></span ></button >
3
3
</template >
4
4
<script lang="ts">
5
5
export default {
6
- props:{
7
- value:Boolean
6
+ props: {
7
+ value: Boolean
8
8
},
9
9
// props和context 传值方式
10
- setup(props ,context ){
11
- const toggle = ()=> {
10
+ setup(props , context ) {
11
+ const toggle = () => {
12
12
// 事件:vue3的v-model改动,之前是input
13
- context .emit (' update:value' , ! props .value )
14
- }
15
- return { toggle }
13
+ context .emit (' update:value' , ! props .value );
14
+ };
15
+ return {toggle };
16
16
}
17
- }
17
+ };
18
18
</script >
19
19
<style lang="scss" scoped>
20
20
$h : 22px ;
21
21
$h2 : $h - 4px ;
22
- button {
22
+ button {
23
23
height : $h ;
24
- width : $h * 2 ;
24
+ width : $h * 2 ;
25
25
border : none ;
26
26
background : #bfbfbf ;
27
27
border-radius : $h / 2 ;
28
28
position : relative ;
29
- }
30
- span {
31
- position : absolute ;
32
- top : 2px ;
33
- left : 2px ;
34
- height : $h2 ;
35
- width : $h2 ;
36
- background :white ;
37
- border-radius : $h2 / 2 ;
38
- transition : all 250ms ;
39
- }
40
- button .checked {
41
- background : #1890ff ;
42
- }
43
- button .checked > span {
44
- left : calc (100% - #{$h2 } - 2px );
45
- }
46
- button :focus {
47
- outline : none ;
48
- }
49
- button :active {
50
- > span {width : $h2 + 4px ;}
51
- }
52
- button .checked :active {
53
- > span {width : $h2 + 4px ; margin-left : -4px ;}
29
+
30
+ > span {
31
+ position : absolute ;
32
+ top : 2px ;
33
+ left : 2px ;
34
+ height : $h2 ;
35
+ width : $h2 ;
36
+ background : white ;
37
+ border-radius : $h2 / 2 ;
38
+ transition : all 250ms ;
39
+ }
40
+
41
+ & .checked {
42
+ background : #1890ff ;
43
+
44
+ > span {
45
+ left : calc (100% - #{$h2 } - 2px );
46
+ }
47
+ }
48
+
49
+ & :focus {
50
+ outline : none ;
51
+ }
52
+
53
+ & :active {
54
+ > span {
55
+ width : $h2 + 4px ;
56
+ }
57
+ }
58
+
59
+ & .checked :active {
60
+ > span {
61
+ width : $h2 + 4px ;
62
+ margin-left : -4px ;
63
+ }
64
+ }
54
65
}
55
66
</style >
You can’t perform that action at this time.
0 commit comments