vuewatch使用教程交流?<script>
import { toRef,toRefs,watch } from "vue";
export default {
props: [title],
setup(props) {
const state = reactive({
listParam: {
searchKey: "",
mainFollower: ""
}
})
const t1 = watch(() => state.listParam.searchKey, (newVal,oldVal) => {
console.log(newVal, oldVal)
state.listParam.searchKey = newVal.trim()
setTimeout(() => {
t1();// 取消監聽
}, 5000)
})
watch([() => state.listParam.customerName, () => state.listParam.mainFollower],
([newCustomerName, newMainFoller],[oldCustomerName,oldMainFoller]) => {
state.listParam.customerName = newCustomerName.trim()
state.listParam.mainFollower = newMainFoller.trim()
},{
immediate: true
})
const t2 = watchEffect(() => {
state.listParam.searchKey = state.listParam.searchKey ? state.listParam.searchKey.trim() : ""
state.listParam.mainFollower= state.listParam.mainFollower? state.listParam.mainFollower.trim() : ""
setTimeout(() => {
t2();// 取消監聽
}, 5000)
})
return {
state
}
},
};
</script>
Copy
,今天小編就來聊一聊關于vuewatch使用教程交流?接下來我們就一起去研究一下吧!
<script>
import { toRef,toRefs,watch } from "vue";
export default {
props: [title],
setup(props) {
const state = reactive({
listParam: {
searchKey: "",
mainFollower: ""
}
})
const t1 = watch(() => state.listParam.searchKey, (newVal,oldVal) => {
console.log(newVal, oldVal)
state.listParam.searchKey = newVal.trim()
setTimeout(() => {
t1();// 取消監聽
}, 5000)
})
watch([() => state.listParam.customerName, () => state.listParam.mainFollower],
([newCustomerName, newMainFoller],[oldCustomerName,oldMainFoller]) => {
state.listParam.customerName = newCustomerName.trim()
state.listParam.mainFollower = newMainFoller.trim()
},{
immediate: true
})
const t2 = watchEffect(() => {
state.listParam.searchKey = state.listParam.searchKey ? state.listParam.searchKey.trim() : ""
state.listParam.mainFollower= state.listParam.mainFollower? state.listParam.mainFollower.trim() : ""
setTimeout(() => {
t2();// 取消監聽
}, 5000)
})
return {
state
}
},
};
</script>
Copy
更多精彩资讯请关注tft每日頭條,我们将持续为您更新最新资讯!