【发布时间】:2017-11-29 22:22:11
【问题描述】:
我在 Vue.js 2.3 中使用 <component v-for="..."> 标签来动态呈现组件列表。
模板如下所示:
<some-component v-for="{name, props}, index in modules" :key="index">
<component :is="name" v-bind="props"></component>
</some-component>
modules 数组在我的组件data() 中:
modules: [
{
name: 'some-thing',
props: {
color: '#0f0',
text: 'some text',
},
},
{
name: 'some-thing',
props: {
color: '#f3f',
text: 'some other text',
},
},
],
我正在使用v-bind={...} 对象语法来动态绑定道具,这非常有效。我还想通过这种方法将事件侦听器与v-on(并使用.sync'd 道具)绑定,但我不知道是否可以不创建自定义指令。
我尝试像这样添加到我的props 对象,但没有成功:
props: {
color: '#f3f',
text: 'some other text',
'v-on:loaded': 'handleLoaded', // no luck
'volume.sync': 'someValue', // no luck
},
我的目标是让用户在侧边栏中使用vuedraggable 重新排序小部件,并将他们的布局偏好保存到数据库中,但有些小部件有@events 和.synced props。这可能吗?我欢迎任何建议!
【问题讨论】:
标签: vue.js vue-component