vue父组件主动获取子组件方法属性
<template><div id="index"><h1>this is index</h1><my-header ref='header'></my-header><button @click=
·
<template>
<div id="index">
<h1>this is index</h1>
<my-header ref='header'></my-header>
<button @click='attack'>触发子组件方法</button>
</div>
</template>
<script>
import myHeader from './header'
export default{
components:{
myHeader
},
data(){
return {
}
},
methods:{
attack(){
console.log(this.$refs.header.msg);
this.$refs.header.fun();
}
}
}
</script>
<template>
<div id='header'>
<h1>this is header</h1>
</div>
</template>
<script>
export default{
data(){
return {
msg:'this is header message'
}
},
methods:{
fun(){
console.log('this is header');
}
}
}
</script>
更多推荐
已为社区贡献4条内容
所有评论(0)