子级元素发生改变,父级元素及时做出相应的响应
1.首先回顾 v-modle, 表单的语句,实时或者延时(.lazy)获得用户输入的信息
2. 侦听器 watch ,实时响应然后做出相关操作
<h3>响应组件</h3>
<Search @Search="myAnser" />
响应:{{ anser }}
</template>
<script>
import Search from './Search.vue';
export default {
data() {
return {
anser: ""
}
},
methods: {
myAnser(search) {
this.anser = search
}
},
components: {
Search,
},
}
</script>
<template>
搜索:
<input type="text" v-model="search">
<br>
</template>
<script>
export default{
data() {
return {
search: ""
}
},
watch: {
search(newValue, oldValue) {
this.$emit("Search",newValue)
}
},
}
</script>
标签:Search,组合,modle,28,search,响应,export,anser
From: https://www.cnblogs.com/zhanjianhai/p/17770518.html