关于VUE三个语法糖

  • 一、冒号":”,是v-bind的缩写,表示标签的属性值取vue的数据属性值
  • <a :href='url'>中华人民共和国</a>
    <a v-bind:href='url'>中华人民共和国</a>
    

    二、@符号,是v-on指令的缩写,表示触发事件

    <button @click="handleClick">中华人民共和国</a>
    
    <a v-on:click='handleClick'>中华人民共和国</a>
    三、#符号,是在使用vue组件的插槽时的v-slot缩写
  • //假如组件<base-layout>定义中使用了具名插槽
    <div class="container">
      <header>
        <slot name="header"></slot>
      </header>
      <main>
        <slot></slot>
      </main>
      <footer>
        <slot name="footer"></slot>
      </footer>
    </div>
     
     
    //我们使用组件的时候就需要如下写法:
    <base-layout>
      <template v-slot:header>
        <h1>生活</h1>
      </template>
     
      <template v-slot:default>
        <p>学习</p>
        <p>www.baidu.com</p>
      </template>
     
      <template v-slot:footer>
        <p>教育</p>
      </template>
    </base-layout>
     
    //我们可以使用#,如下:
    <base-layout>
      <template #header>
        <h1>汽车</h1>
      </template>
     
      <template #default>
        <p>用品</p>
        <p>www.wanmait.com</p>
      </template>
     
      <template #footer>
        <p>服务</p>
      </template>
    </base-layout>

  • 2
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值