File tree Expand file tree Collapse file tree 2 files changed +37
-2
lines changed Expand file tree Collapse file tree 2 files changed +37
-2
lines changed Original file line number Diff line number Diff line change @@ -26,6 +26,14 @@ createComponent({
2626 disabled : {
2727 type : Boolean ,
2828 value : false
29+ } ,
30+ /**
31+ * @description 点击后是否需要更改 value
32+ * @optional true/false
33+ */
34+ changeOnClick : {
35+ type : Boolean ,
36+ value : true
2937 }
3038 } ,
3139 data : {
@@ -68,10 +76,18 @@ createComponent({
6876 } ,
6977 methods : {
7078 toggleSwitch ( ) {
71- if ( this . disabled )
79+ if ( this . disabled ) {
80+ this . triggerEvent ( 'click' , { value : this . isOn } ) ;
81+ return ;
82+ }
83+ if ( ! this . changeOnClick ) {
84+ this . triggerEvent ( 'click' , { value : this . isOn } ) ;
7285 return ;
86+ }
7387 const newValue = ! this . isOn ;
7488 this . isOn = newValue ;
89+ // 当开关有点击时触发
90+ this . triggerEvent ( 'click' , { value : newValue } ) ;
7591 // 当开关状态变化时触发
7692 this . triggerEvent ( 'change' , { value : newValue } ) ;
7793 // 当开关状态变化时触发
Original file line number Diff line number Diff line change @@ -27,6 +27,14 @@ createComponent({
2727 disabled : {
2828 type : Boolean ,
2929 value : false
30+ } ,
31+ /**
32+ * @description 点击后是否需要更改 value
33+ * @optional true/false
34+ */
35+ changeOnClick : {
36+ type : Boolean ,
37+ value : true
3038 }
3139 } ,
3240 data : {
@@ -67,9 +75,20 @@ createComponent({
6775 } ,
6876 methods : {
6977 toggleSwitch ( ) {
70- if ( this . disabled ) return
78+ if ( this . disabled ) {
79+ this . triggerEvent ( 'click' , { value : this . isOn } )
80+ return
81+ }
82+
83+ if ( ! this . changeOnClick ) {
84+ this . triggerEvent ( 'click' , { value : this . isOn } )
85+ return
86+ }
87+
7188 const newValue = ! this . isOn
7289 this . isOn = newValue
90+ // 当开关有点击时触发
91+ this . triggerEvent ( 'click' , { value : newValue } )
7392 // 当开关状态变化时触发
7493 this . triggerEvent ( 'change' , { value : newValue } )
7594 // 当开关状态变化时触发
You can’t perform that action at this time.
0 commit comments