vue动态创建组件(运⾏时创建组件)function mountCmp (cmp, props, parent) {
if (cmp.default) {
nodeselector
cmp = cmp.default
}
cmp = d(cmp)
let node = ateElement('div')
parent.appendChild(node)
new cmp({ // eslint-disable-line
el: node,
propsData: props,
parent: this
})
}
import('../components/title').then(cmp => {
mountCmp.call(this, cmp, {title: 123456}, document.querySelector('.child-host'))
mountCmp.call(this, cmp, {title: 123456}, document.querySelector('.child-host'))
})
//title.vue
<template>
<div class="title">
<div class="title-icon"></div>
<div class="title-txt">{{title}}</div>
<div class="title-dotline"> </div>
</div>
</template>
<script>
export default {
props: ['title']
}
</script>
function mountCmp (cmp, props, parent) {
cmp = d(cmp.default)
let node = ateElement('div')
parent.appendChild(node)
new cmp({ // eslint-disable-line
el:node,
propsData:props,
parent:this
})
}

版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。