Skip to content

Commit

Permalink
fix(Switch): 修复 onMounted 初始值设置不生效的问题
Browse files Browse the repository at this point in the history
  • Loading branch information
ocean-gao committed Nov 1, 2024
1 parent 5657dca commit 37464c6
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 2 deletions.
2 changes: 1 addition & 1 deletion components/switch/switch.vue
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ export default defineComponent({
const { validate, isFormDisabled } = useFormAdaptor();
onMounted(() => {
// 默认为未选中
if (currentValue.value === undefined) {
if (currentValue.value === undefined && props.inactiveValue !== undefined) {
// 避免可能出现的bug https://github.com/vuejs/core/issues/5290
nextTick(() => {
updateCurrentValue(props.inactiveValue);
Expand Down
5 changes: 4 additions & 1 deletion docs/.vitepress/components/switch/common.vue
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,17 @@
</template>

<script>
import { ref } from 'vue';
import { onMounted, ref } from 'vue';
export default {
setup() {
const val = ref();
const handleChange = (value) => {
console.log('[switch.common] [handleChange] value:', value);
};
onMounted(() => {
val.value = true;
});
return {
val,
handleChange,
Expand Down

0 comments on commit 37464c6

Please sign in to comment.