vue 父組件調用子組件的函數
阿新 • • 發佈:2018-08-21
func div port brush nts imp spa htm som
子組件
<template> <div> child </div> </template> <script> export default { name: "child", props: "someprops", methods: { childFunction(e) { console.log(e,"ying") } } } </script>
父組件
<template>
<div>
<button @click="clickParent">點擊</button>
<child ref="mychild"></child>
</div>
</template>
<script>
import Child from ‘./child‘;
export default {
name: "parent",
components: {
child: Child
},
methods: {
clickParent() {
this.$refs.mychild.childFunction("父組件調用");//過this.$refs.ref.method調用
}
}
}
</script>
vue 父組件調用子組件的函數