问题:vue通过<router-view></router-view> 渲染成的子组件,如何向父组件传值?
描述:
<div class="goods-serve-body">
<div class="goods-serve-bod-top">
<div>
**<span @click="switchRoute('goods')">产品</span>
<span @click="switchRoute('serve')">服务</span>**
</div>
<div>
<input type="text" placeholder="商品名称"
v-model="searchData">
<span @click="searchData_fun(searchData)">查询</span>
</div>
<div style="clear:both;"></div>
</div>
<div>
**<router-view></router-view>**
</div>
</div>
通过<router-view></router-view> 变换不同的组件,如何将子组件的值传给父组件?
<router-view></router-view>
是用来切换路由,其实你可以不用</router-view>
,写个if else判断,根据不同的参数渲染不同的组件。如果你非要用router-view来和父组件通信,可以通过$on $emit或者url传参或者localstorage或者vuex等来做组件间的通信。望采纳