我有一堆字段要显示为长格式,每个字段允许用户从该字段的值列表中进行选择。
所以基本的事情看起来像这样:
sourceFields
然后在页面中,它使用<div id="app">
<div class="container-fluid">
<master-field v-for="item in sourceFields" :key="item.id"></master-field>
</div>
</div>
数据逐个吐出字段:
item.id
如何从master-field
组件中访问console.log(item.id)
?如果我尝试从组件中的mounted
挂钩执行del
,则说明项目未定义。
答案 0 :(得分:1)
你必须通过道具传递它。 Props Documentation
伪示例:
<my-component :info="someInfo" />
然后在组件中:
Vue.component('myComponent', {
// declare the props
props: ['info'],
template: '<span>{{ info }}</span>'
})