vue中动态添加组件
效果:代码:<template><div><divv-for="(item,index)inlst"><h4>{{item.id}}</h4><leave></leave></div><hr>...
·
效果:
代码:
<template> <div> <div v-for="(item,index) in lst"> <h4>{{item.id}}</h4> <leave></leave> </div> <hr> <button @click="create">创建</button> </div> </template> <script> import leave from './components/leave.vue' export default { name: 'createComponent', data() { return { lst: [{ "id": "1" }], num: 1 } }, components: { leave }, methods: { create() { this.num++; this.lst.unshift({ "id": this.num }); } } } </script> <style scoped> </style>
转载于:https://blog.51cto.com/11871779/2325001
更多推荐
已为社区贡献893条内容
所有评论(0)