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