父子组件通信方式二
<template>
<div>
<h1>{{title}}
<button>emit</button>
<input type="text" ref="input">
</h1>
child
</div>
</template>
<script>
export default {
props: ["title"],
methods: {
getTitle() {
return this.title
},
},
}
</script>
<style lang="scss" scoped>
</style>
<template>
<div>
Parent
<Child title="my name is Parent" ref="compA"></Child>
</div>
</template>
<script>
import Child from "./Child";
export default {
components: {
Child,
},
mounted () {
console.log(this.$refs.compA.getTitle());
this.$refs.input.focus();
},
}
</script>
<style lang="scss" scoped>
</style>