元件,自定義元素。可以拓展html元素,封裝重複可用的**,提高**復用率。
所有的vue元件例項都是vue的例項,因此他們擁有和頁面相同的宣告週期鉤子函式
一、全域性註冊
1、編寫元件:tema.vue
2、註冊:(在入口檔案main.js中)
全域性元件註冊
div>
template>
3、引用import tema from
'./components/tema';
vue.component('tema',tema);
// vue.component為全域性api,獲取或者註冊全域性元件
// vue.component(元件名稱,要註冊的元件);
二、區域性元件註冊
tema>
若只需要在當前的作用域下使用該元件的話,建議註冊區域性元件。
1、編寫元件:tema.vue
2、註冊、使用
區域性元件註冊
div>
template>
// 註冊
import tema from
'./tema';
export default
},components:
}
// 使用
tema>
十 元件註冊
1.全域性元件註冊 1.template寫在div中通過template compnenta componenta div componenta this is component div template vue.component componenta methods newvue script...
Vue 3 元件註冊
上一節實驗中,我們大概了解了一下元件的基礎,這一節實驗我們要深入元件註冊。我們在註冊元件的時候,我們都會給元件起乙個名字,就好像我們人的名字一樣。需要注意的是,我們的元件名字是有一些規範的,一般這種單檔案元件,我們強烈推薦使用字母全小寫且必須包含乙個連字元,全部小寫字母,單詞使用中華線 隔開。例如我...
Vue學習筆記 6 元件註冊
3.基礎元件的自動化全域性註冊 我們前一篇提到了元件註冊,但是那裡用的是我們的全域性註冊。註冊分為區域性註冊和全域性註冊 下面開始講解 lang en charset utf 8 titletitle src script head v for i in names v bind value i x...