是否可以在Vue.JS的另一个组件中声明组件? 这就是我想要做的事:可重复使用的嵌套VueJS组件
<!-- 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'
)
现在我用的巨大的一行'模板:“......”',它工作正常,但如果有谁知道没有更好的办法创建额外的文件... – andrei