Vue我手动创建了一个自定义组件标签,怎么才能运行起来

2025-05-13 06:51:06
推荐回答(1个)
回答1:

自定义组件是需要先注册才能使用的,分全局注册和局部注册。
全局注册:
Vue.component('my-component', {
// 选项
})

new Vue({
el: '#some-element',
// 选项
})





局部注册:

var Child = {
template: '
A custom component!
'
}
new Vue({
// ...
components: {
// 将只在父模板可用
'my-component': Child
}
})