方法一:文本框監(jiān)聽,使用@input
事件文章來源:http://www.zghlxwxcb.cn/news/detail-692260.html
<template>
<view>
<input type="text" v-model="wip_entity_name" @input="handleInputChange" />
</view>
</template>
<script>
export default {
data() {
return {
wip_entity_name: '' // 文本框綁定的數(shù)據(jù)
};
},
methods: {
handleInputChange() {
// 執(zhí)行需要在文本框值改變時(shí)執(zhí)行的方法
console.log('文本框的值發(fā)生改變');
// 調(diào)用其他方法
this.otherMethod();
},
otherMethod() {
// 實(shí)現(xiàn)其他方法的邏輯
console.log('執(zhí)行其他方法');
}
}
};
</script>
方法二:使用watch監(jiān)聽屬性(很好解決了文本框中數(shù)據(jù)非手輸時(shí)監(jiān)聽不到數(shù)據(jù)變化)文章來源地址http://www.zghlxwxcb.cn/news/detail-692260.html
<template>
<view>
<input type="text" v-model="wip_entity_name" />
</view>
</template>
<script>
export default {
data() {
return {
wip_entity_name: '' // 文本框綁定的數(shù)據(jù)
};
},
watch: {
wip_entity_name(newVal, oldVal) {
// 監(jiān)聽文本框值的改變
if (newVal !== oldVal) {
// 執(zhí)行需要在文本框值改變時(shí)執(zhí)行的方法
console.log('文本框的值發(fā)生改變');
// 調(diào)用其他方法
this.otherMethod();
}
}
},
methods: {
otherMethod() {
// 實(shí)現(xiàn)其他方法的邏輯
console.log('執(zhí)行其他方法');
}
}
};
</script>
到了這里,關(guān)于uni-app:監(jiān)聽數(shù)據(jù)變化(watch監(jiān)聽、@input事件)的文章就介紹完了。如果您還想了解更多內(nèi)容,請(qǐng)?jiān)谟疑辖撬阉鱐OY模板網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關(guān)文章,希望大家以后多多支持TOY模板網(wǎng)!