需求的话是这样的 右边的封装成组件 点击+ 可以无限制复制 自己 到右边
我在组件中引用了自己 但是会报错 怎么解决?
组件是这样的:
<template>
<div class="c1" >
<input type="text">
<i class="el-icon-circle-plus" @click="add('a-component')" ></i>
<ul class="main-pic">
<li :is="item.component" v-for="item in allComponents"></li>
</ul>
</div>
</template>
<script>
// component1就是这个组件本身
import AComponent from './component1.vue'
export default {
name: 'Node',
components: {
'a-component': AComponent,
},
data () {
return {
allComponents: [],
}
},
methods: {
add(component) {
this.allComponents.push({
'component': component,
})
}
}
}
</script>
<!-- Add "scoped" attribute to limit CSS to this component only -->
<style scoped>
.domDiv{
height: 20px;
width: 400px;
}
input{
border: none;
border-bottom: 1px solid #ccc;
width: 100px;
}
.el-icon-circle-plus{
color: green;
}
.c1{
height: 50px;
width: 200px;
}
</style>
vue的组件操作应该是这样:
你的需求是复制DOM结构,而不是复制vue组件。
根据你的代码,我给你提供个思路,动态循环组件:
template
methods