mirror of
https://gitee.com/ssssssss-team/magic-boot.git
synced 2025-02-22 02:32:49 +08:00
修复switch 选择问题
This commit is contained in:
parent
fdc64b9143
commit
f338e97208
@ -1,8 +1,8 @@
|
||||
<template>
|
||||
<el-switch
|
||||
v-model="selectValue"
|
||||
:active-value="activeValue + ''"
|
||||
:inactive-value="inactiveValue + ''"
|
||||
:active-value="_activeValue"
|
||||
:inactive-value="_inactiveValue"
|
||||
v-bind="props.props"
|
||||
/>
|
||||
</template>
|
||||
@ -17,10 +17,39 @@ const props = defineProps({
|
||||
inactiveValue: Boolean | String | Number,
|
||||
props: Object
|
||||
})
|
||||
const _activeValue = ref(true)
|
||||
const _inactiveValue = ref(false)
|
||||
|
||||
function setActive(value){
|
||||
if(typeof(value) == 'boolean'){
|
||||
if(props.activeValue == undefined && props.inactiveValue == undefined){
|
||||
_activeValue.value = true
|
||||
_inactiveValue.value = false
|
||||
}else{
|
||||
_activeValue.value = props.activeValue
|
||||
_inactiveValue.value = props.inactiveValue
|
||||
}
|
||||
}else{
|
||||
if(value || value == 0){
|
||||
if(props.activeValue == undefined && props.inactiveValue == undefined){
|
||||
_activeValue.value = '1'
|
||||
_inactiveValue.value = '0'
|
||||
}else{
|
||||
_activeValue.value = props.activeValue + ''
|
||||
_inactiveValue.value = props.inactiveValue + ''
|
||||
}
|
||||
}else{
|
||||
_activeValue.value = true
|
||||
_inactiveValue.value = false
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
dynamicSetValue(props.modelValue)
|
||||
setActive(props.modelValue)
|
||||
watch(() => props.modelValue, (value) => {
|
||||
dynamicSetValue(value)
|
||||
setActive(value)
|
||||
})
|
||||
function dynamicSetValue(value){
|
||||
if(typeof(value) == 'boolean'){
|
||||
@ -28,6 +57,8 @@ function dynamicSetValue(value){
|
||||
}else{
|
||||
if(value || value == 0){
|
||||
selectValue.value = value + ''
|
||||
}else{
|
||||
selectValue.value = false
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user