$listeners父传子和子改父
$bus组件共享参数
父组件里
<helloworld @msg="msg" @send="send" :name="name"></helloworld>
import helloworld from "../components/HelloWorld";
components: {
helloworld
},
data() {
return {
msg: "父组件的值",
far: "父组件"
};
},
methods: {
send(val) {
this.msg = val;
}
},
mounted() {
this.$bus.$on("goto", data => {
this.far = data;
});
},
子组件里
<button @click="update">改变父组件的值</button>
props: {
data() {
return {
content: "子组件的值",
cont: "改变之后"
};
},
methods: {
update() {
this.$listeners.send(this.content);
this.$bus.$emit("goto", this.cont);
}
},
mounted() {
console.log(this.$listeners.msg.fns);
console.log(this.$attrs)
},