vue2表单元素列表

时间:2018-03-06 17:19:25

标签: javascript vue.js vuejs2 vue-component

我有一堆字段要显示为长格式,每个字段允许用户从该字段的值列表中进行选择。

所以基本的事情看起来像这样:

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,则说明项目未定义。

1 个答案:

答案 0 :(得分:1)

你必须通过道具传递它。 Props Documentation

伪示例:

<my-component :info="someInfo" />

然后在组件中:

Vue.component('myComponent', {
  // declare the props
  props: ['info'],
  template: '<span>{{ info }}</span>'
})