怎么在Vue中創(chuàng)建一個頭部組件?相信很多沒有經驗的人對此束手無策,為此本文總結了問題出現(xiàn)的原因和解決方法,通過這篇文章希望你能解決這個問題。
Vue.js 組件
組件(Component)是 Vue.js 最強大的功能之一。
組件可以擴展 HTML 元素,封裝可重用的代碼。
具體代碼如下所示:
<!DOCTYPE html> <html> <head> <meta charset="utf-8" /> <meta http-equiv="X-UA-Compatible" content="IE=edge"> <title>Page Title</title> <meta name="viewport" content="width=device-width, initial-scale=1"> <script src="https://cdn.jsdelivr.net/npm/vue@2.5.17/dist/vue.js"></script> <style> * { margin: 0; padding: 0; } li { list-style: none } body { height: 2000px; overflow: hidden; } .header { width: 100%; height: 40px; background: #e1e1e1; text-align: center; line-height: 40px; position: fixed; } .header button { padding: 0rem 0.2rem; height: 40px; top: 0; } .header button:nth-of-type(1) { position: fixed; left: 0; } .header button:nth-of-type(2) { position: fixed; right: 0; } </style> </head> <body> <div id="app"> <custom-header :title="title"> <button slot="left">返回</button> </custom-header> </div> <template id="header"> <div class="header"> <slot name="left"></slot> <span>{{title}}</span> <slot name="right"></slot> </div> </template> <script> Vue.component("custom-header", { template: '#header', props: ["title"] }); //多插槽的使用,則使用name屬性來指定要插入的位置 var vm = new Vue({ el: '#app', data: { title: "通訊錄" }, components: { } }); </script> </body> </html>
看完上述內容,你們掌握怎么在Vue中創(chuàng)建一個頭部組件的方法了嗎?如果還想學到更多技能或想了解更多相關內容,歡迎關注創(chuàng)新互聯(lián)成都網站設計公司行業(yè)資訊頻道,感謝各位的閱讀!
另外有需要云服務器可以了解下創(chuàng)新互聯(lián)scvps.cn,海內外云服務器15元起步,三天無理由+7*72小時售后在線,公司持有idc許可證,提供“云服務器、裸金屬服務器、高防服務器、香港服務器、美國服務器、虛擬主機、免備案服務器”等云主機租用服務以及企業(yè)上云的綜合解決方案,具有“安全穩(wěn)定、簡單易用、服務可用性高、性價比高”等特點與優(yōu)勢,專為企業(yè)上云打造定制,能夠滿足用戶豐富、多元化的應用場景需求。
分享名稱:怎么在Vue中創(chuàng)建一個頭部組件-創(chuàng)新互聯(lián)
網頁鏈接:http://www.rwnh.cn/article16/dcehdg.html
成都網站建設公司_創(chuàng)新互聯(lián),為您提供移動網站建設、網站維護、網站營銷、商城網站、做網站、面包屑導航
聲明:本網站發(fā)布的內容(圖片、視頻和文字)以用戶投稿、用戶轉載內容為主,如果涉及侵權請盡快告知,我們將會在第一時間刪除。文章觀點不代表本網站立場,如需處理請聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內容未經允許不得轉載,或轉載時需注明來源: 創(chuàng)新互聯(lián)