【发布时间】:2023-04-04 01:12:01
【问题描述】:
是否可以在 Vue.JS 中的另一个组件中声明一个组件? 这就是我想要做的:
<!-- this is declared inside some-component.vue file -->
<script>
export default {
components:{
'cmptest' : {
template:'#cmptest',
props:['mprop']
}
},
data : () => ({
val:'world'
})
};
</script>
<template>
<div>
<template id="cmptest">
{{mprop}}
</template>
<cmptest mprop="hello"></cmptest>
<cmptest :mprop="val"></cmptest>
</div>
</template>
如果可能,我想避免全局注册子组件(使用Vue.component(...))
换句话说,我想在父组件文件中指定孩子的<template>(不用写一大行template:'entire-html-of-child-component-here')
【问题讨论】:
-
现在我使用了巨大的单线
template:'....'并且工作正常,但如果有人知道更好的方法而无需创建额外的文件...
标签: vue.js vuejs2 vue-component