fix: 修复Switch会在每次刷新后发送请求
This commit is contained in:
@@ -191,20 +191,30 @@ function setBtnStatus(idx: number, isOn: boolean) {
|
||||
}
|
||||
|
||||
// 监听 props 变化只同步一次
|
||||
const isFirstEnableDigitalTwin = ref(true);
|
||||
watch(
|
||||
() => props.enableDigitalTwin,
|
||||
(newVal) => {
|
||||
const client = getClient();
|
||||
client.setEnable(newVal);
|
||||
if (isFirstEnableDigitalTwin.value) {
|
||||
isFirstEnableDigitalTwin.value = false;
|
||||
} else {
|
||||
const client = getClient();
|
||||
client.setEnable(newVal);
|
||||
}
|
||||
},
|
||||
{ immediate: true },
|
||||
);
|
||||
|
||||
const isFirstUpdateStatus = ref(true);
|
||||
watch(
|
||||
() => [switchCount.value, props.initialValues],
|
||||
() => {
|
||||
btnStatus.value = parseInitialValues();
|
||||
updateStatus(btnStatus.value);
|
||||
if (isFirstUpdateStatus.value) {
|
||||
isFirstUpdateStatus.value = false;
|
||||
} else {
|
||||
updateStatus(btnStatus.value);
|
||||
}
|
||||
},
|
||||
);
|
||||
</script>
|
||||
|
||||
Reference in New Issue
Block a user