在component里面有多種情況,其實很多情況下都是從別的組件導入此組件
- 導入組件
本組件寫
<script>
const heard = { template: '<div>this is heardComponent</div>' }
</script>
導入組件
<script>
import heard from './components/heard.vue'
</script>
- 注冊component
全局注冊組件
<script>
import Vue from 'vue'
Vue.component ('heard',{
template: heard
})
</script>
局部注冊component
<script>
new Vue ({
el:'#app',
components: {
'heard': heard
}
})
</script>
- 使用component
// xxx.vue 文件里面使用
<div id="app">
<heard></heard
</div>