【发布时间】:2022-01-08 07:06:19
【问题描述】:
我使用watch 来跟踪输入元素值,每次值更改时都会触发该值。有没有办法显式调用watch?
喜欢:
点击事件 --> isDataChanged --> 调用 watch --> 如果 ref 改变则返回 true
<template>
<input type="text" v-model="userInput" />
<button @click="isChanged">change</button>
<p></p>
</template>
<script>
import { watch, ref } from "@vue/runtime-core";
export default {
setup() {
const userInput = ref("");
const isChanged = ()=> {
// call watch function
console.log("changed")
}
watch([userInput], (newValues, prevValues) => {
if (newValues) {
console.log(newValues)
return true;
}
});
return {
userInput,
isChanged,
};
},
};
</script>
【问题讨论】:
标签: vue.js vuejs3 vue-composition-api vue-reactivity