Vue中注冊全局組件的三種方式
更新時間:2023年11月17日 10:29:06 作者:Kratial
這篇文章主要介紹了Vue中注冊全局組件的三種方式,本文通過實例代碼給大家介紹的非常詳細(xì),對大家的學(xué)習(xí)或工作具有一定的參考借鑒價值,需要的朋友可以參考下
1.方式一
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>Vue組件的注冊</title> <script src="../vue.js"></script> </head> <body> <template id="Mydemo"> <h1>Hello Time</h1> </template> <div id="app"> <account></account> </div> <script> //注冊全局組件 Vue.component('account',{ template:"#Mydemo", }) new Vue({ el:"#app", }) </script> </body> </html>
2.方式二
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>Vue組件的注冊</title> <script src="../vue.js"></script> </head> <body> <div id="app"> <say-hello></say-hello> </div> <script> //注冊全局組件 Vue.component('say-hello',{ template:"<h2>Hello everyone</h2>", }); //根實例 new Vue({ el:"#app", }) </script> </body> </html>
3.方式三:
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>Vue組件的注冊</title> <script src="../vue.js"></script> </head> <body> <div id="app"> <my-list></my-list> </div> <script> var list=Vue.extend({ template:'<h1>this is a list</h1>', }); Vue.component("my-list",list); //根實例 new Vue({ el:"#app", }) </script> </body> </html>
到此這篇關(guān)于Vue中注冊全局組件的三種方式的文章就介紹到這了,更多相關(guān)vue注冊全局組件內(nèi)容請搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!
相關(guān)文章
vue-cli項目使用vue-picture-preview圖片預(yù)覽組件方式
這篇文章主要介紹了vue-cli項目使用vue-picture-preview圖片預(yù)覽組件方式,具有很好的參考價值,希望對大家有所幫助。如有錯誤或未考慮完全的地方,望不吝賜教2022-09-09vue實現(xiàn)點擊導(dǎo)航欄滾動頁面到指定位置的功能(推薦)
這篇文章主要介紹了vue實現(xiàn)點擊導(dǎo)航欄滾動頁面到指定位置的功能(推薦),步驟一是是通過獲取不同板塊的滾輪高度,步驟二通過編寫執(zhí)行滾動操作的函數(shù),結(jié)合實例代碼給大家介紹的非常詳細(xì),需要的朋友可以參考下2023-11-11Vue入門學(xué)習(xí)筆記【基本概念、對象、過濾器、指令等】
這篇文章主要介紹了Vue入門學(xué)習(xí)筆記,結(jié)合實例形式分析了vue.js的基本概念、對象、過濾器、指令等的相關(guān)原理與簡單使用方法,需要的朋友可以參考下2019-04-04