
比如有组件 C 和 D ,他们根据传入的数据不同,界面也不一样。 现在组件 B 里 import 组件 C 和 D ,请问如何在 js 代码里给 C , D 组件传递数据呢?
<template> <div> <component :is="currentView"></component> </div> </template> <script> import C from './C.vue' import D from './D.vue' export default { data() { return { currentView:null } }, methods: { clickSwitch(row, event){ if(row.type==='c'){ this.currentView = C; //这里如果给 C 组件传送数据呢? }else{ this.currentView = D;//这里如果给 D 组件传送数据呢? } } } } </script> 1 readonly 2016-11-03 08:31:09 +08:00 via iPhone is 只接收字符串吧!那么属性就是写在 component 上面了 |
2 hxsf 2016-11-03 08:33:31 +08:00 via iPhone v-if 可破 |
3 Troevil 2016-11-03 08:34:05 +08:00 component 内定义 props :{ xx:{ type:String } } , 然后 调用时 可用 < component :xx="aa" > aa 可以为变量或者字符串等 |