Vue组件模板

本文章主要介绍组件模板的书写方式

以下为实现页面效果

以下为html代码和js代码的集合

<body>
<div id="app">
    <!--使用外部模板-->
    <v-com></v-com>
    <!--使用js内部模板-->
    <v-header></v-header>
    <v-content></v-content>
    <v-footer></v-footer>
    <v-rua></v-rua>
</div>
<!--外部编写模板-->
<template id="vmm" v-if="false">
    <div>
        <h1>我是外面的模板</h1>
        <p>我是外面的内容</p>
    </div>
</template>
</body>
<!--加载vue-->
<script src="js/vue.js"></script>
<script>
    //1.构造结构
   let header=Vue.extend({
        template:"<h1>我是一个小组件</h1>"

    });
    let content=Vue.extend({
        template:"<h1>我是一个小组件内容</h1>"

    });
    let footer=Vue.extend({
        template:"<h1>我是一个小组件尾巴</h1>"

    });
    //2.注册为组件
    Vue.component("vHeader",header);
    Vue.component("vContent",content);
    Vue.component("vFooter",footer);

    //3.构造和注册同时使用
    Vue.component("vRua",{
        template:"<p>我是语法糖构造出来的</p>"
    });

    //4.使用html构造结构编写
    Vue.component("vCom",{
        template:"#vmm"
    });

    new Vue({
        el:"#app",
    })

</script>

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值