我在我的 vue 实例中创建了一个组件。
components: {
plan: {
template: "#suggested-properties",
props: ['plan', 'active'],
computed: {
isActive: function(){
return this.plan.name == this.active.name;
}
},
methods: {
setActivePlan: function(){
var that = this;
that.activeParameter= true;
this.active = this.plan;
}
}
}
}
有没有一种方法可以通过单击按钮时传递数据来动态创建相同组件的实例?
最佳答案
希望我能正确理解您的问题,您只需要遍历一个数组即可。
data: {
numOfComps: 0
}
并在您的 HTML 中:
<component v-for="comp in numOfComps></component>
检查 fiddle 的工作示例:
http://jsfiddle.net/gc2t8o5t/
关于vue.js - 如何动态创建vue组件,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/33640094/