1.父级页面传给子页面传参并使用子页面方法
子页面接受用props
父级直接this.$refs.xx.xx()
来调用子页面方法
2.子级页面传给父页面传参并使用父页面方法
子页面调用$emit传值给父级
父页面provide来提供方法子页面inject来接受方法
父级页面:
<child ref=‘detail’ :params="val"></child>
import detailVue from 'xxl'
components:{detailVue},
//引用子组件
this.$nextTick(()=>{ //当子组件用v-if时每次都能调用
this.$refs.detail.init();
})
//调用子组件的方法
//子页面
props:['params'], //获取传参
这是父页面
<template>
<div>
<div class="father-box">
<span>这是父级页面</span>
<span>{
{textp}}</span>
<div>{
{msg.name}}</div>
<button @click="fatherClick">点我弹出子页面的方法</button>
</div>
<child ref='refChild' @sendMsg="getSonmsg" :num='num'></child>
</div>
</template>
<script>
im