77 computed ,
88 onMounted ,
99 nextTick ,
10+ watch ,
1011} from 'vue' ;
1112import LoadingOutlined from '@ant-design/icons-vue/LoadingOutlined' ;
1213import PropTypes from '../_util/vue-types' ;
@@ -27,7 +28,6 @@ const switchProps = {
2728 checkedChildren : PropTypes . any ,
2829 unCheckedChildren : PropTypes . any ,
2930 tabindex : PropTypes . oneOfType ( [ PropTypes . string , PropTypes . number ] ) ,
30- defaultChecked : PropTypes . looseBool ,
3131 autofocus : PropTypes . looseBool ,
3232 loading : PropTypes . looseBool ,
3333 checked : PropTypes . looseBool ,
@@ -59,6 +59,14 @@ const Switch = defineComponent({
5959 '`value` is not validate prop, do you mean `checked`?' ,
6060 ) ;
6161 } ) ;
62+ const checked = ref ( props . checked !== undefined ? ! ! props . checked : ! ! attrs . defaultChecked ) ;
63+
64+ watch (
65+ ( ) => props . checked ,
66+ ( ) => {
67+ checked . value = ! ! props . checked ;
68+ } ,
69+ ) ;
6270
6371 const configProvider = inject ( 'configProvider' , defaultConfigProvider ) ;
6472 const { getPrefixCls } = configProvider ;
@@ -75,9 +83,6 @@ const Switch = defineComponent({
7583 const prefixCls = computed ( ( ) => {
7684 return getPrefixCls ( 'switch' , props . prefixCls ) ;
7785 } ) ;
78- const checked = computed ( ( ) => {
79- return 'checked' in props ? ! ! props . checked : ! ! props . defaultChecked ;
80- } ) ;
8186
8287 onMounted ( ( ) => {
8388 nextTick ( ( ) => {
@@ -91,6 +96,9 @@ const Switch = defineComponent({
9196 if ( props . disabled ) {
9297 return ;
9398 }
99+ if ( props . checked === undefined ) {
100+ checked . value = check ;
101+ }
94102 emit ( 'update:checked' , check ) ;
95103 emit ( 'change' , check , e ) ;
96104 } ;
0 commit comments