首頁 > web前端 > js教程 > 主體

Vue如何建立頭部組件?建立頭部組件的方法(程式碼範例)

青灯夜游
發布: 2018-10-24 17:06:43
轉載
2485 人瀏覽過

這篇文章帶給大家的內容是介紹Vue如何創建頭部組件?建立頭部組件的方法(程式碼範例)。有一定的參考價值,有需要的朋友可以參考一下,希望對你們有幫助。

<!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>
    <p id="app">
        <custom-header :title="title">
            <button slot="left">返回</button>
        </custom-header>
    </p>

    <template id="header">
        <p class="header">
            <slot name="left"></slot>
            <span>{{title}}</span>
            <slot name="right"></slot>
        </p>
    </template>

    <script>
        Vue.component("custom-header", {
            template: '#header',
            props: ["title"]
        });        //多插槽的使用,则使用name属性来指定要插入的位置
        var vm = new Vue({
            el: '#app',
            data: {
                title: "通讯录"
            },
            components: {

            }
        });    </script></body></html>
登入後複製

以上是Vue如何建立頭部組件?建立頭部組件的方法(程式碼範例)的詳細內容。更多資訊請關注PHP中文網其他相關文章!

相關標籤:
來源:cnblogs.com
本網站聲明
本文內容由網友自願投稿,版權歸原作者所有。本站不承擔相應的法律責任。如發現涉嫌抄襲或侵權的內容,請聯絡admin@php.cn
熱門教學
更多>
最新下載
更多>
網站特效
網站源碼
網站素材
前端模板
關於我們 免責聲明 Sitemap
PHP中文網:公益線上PHP培訓,幫助PHP學習者快速成長!