解决 cl-input-number 首次触发 onChange 的问题

This commit is contained in:
icssoa
2025-08-20 17:32:55 +08:00
parent 3200ab2bf8
commit 717d8cf932
3 changed files with 14 additions and 8 deletions

View File

@@ -1,6 +1,6 @@
{
"name": "cool-unix",
"version": "8.0.11",
"version": "8.0.12",
"license": "MIT",
"scripts": {
"build-ui": "node ./uni_modules/cool-ui/scripts/generate-types.js",

View File

@@ -28,6 +28,7 @@
})
}
}"
@change="onChange"
></cl-input-number>
</view>
@@ -78,11 +79,15 @@ import { t } from "@/locale";
const num = ref(0);
const isStep = ref(false);
const isMin = ref(true);
const isMin = ref(false);
const isMax = ref(false);
const isDigit = ref(false);
const isInput = ref(true);
const isDisabled = ref(false);
const isSize = ref(false);
const isCustom = ref(false);
function onChange(value: number) {
console.log(value);
}
</script>

View File

@@ -226,13 +226,14 @@ function update() {
val = parseFloat(val.toFixed(2));
}
// 更新绑定
if (val != value.value) {
value.value = val;
}
// 更新值,确保值是数字
value.value = val;
emit("update:modelValue", val);
emit("change", val);
// 如果值发生变化,则触发事件
if (val != props.modelValue) {
emit("update:modelValue", val);
emit("change", val);
}
});
}