Vue3.0新增特性——Fragment模版碎片

Vue3新增特性——Fragment模版碎片

  • vue2中组件的模版必须有一个唯一的跟标签
  • vue3中组件模版可以有多个跟标签

Vue3实例

<!-- home.vue  -->
<template>
  <h1>{{msg}}</h1>
  <h1>{{text}}</h1>
</template>

<script>
  export default {
    data() {
      return {
        msg: 'hello Vue3',
        text: '你好 Vue3'
      }
    },
  }
</script>

<style scoped>
</style>
<!-- App.vue  -->
<script setup>
  // 一旦在script标签上,添加了setup属性,则不需要手动注册子组件
  import Home from './components/Home.vue'
</script>

<template>
  <div>
    <img alt="Vue logo" src="./assets/logo.png">
    <Home />
  </div>
</template>
<style>
  #app {
    font-family: Avenir, Helvetica, Arial, sans-serif;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
    text-align: center;
    color: #2c3e50;
    margin-top: 60px;
  }
</style>

Vue2实例


<!--  App.vue -->
<script>

  // 一旦在script标签上,添加了setup属性,则不需要手动注册子组件
  import Home from './components/Home.vue'
  export default {
    name: 'App',
    components: {
      Home
    }

  }
</script>

<template>
  <div>
    <img alt="Vue logo" src="./assets/logo.png">
    <Home />
  </div>
</template>
<style>
  #app {
    font-family: Avenir, Helvetica, Arial, sans-serif;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
    text-align: center;
    color: #2c3e50;
    margin-top: 60px;
  }
</style>
<!-- home.vue  -->
<template>
  <div>
    <h1>{{msg}}</h1>
    <h1>{{text}}</h1>
  </div>
</template>

<script>
  export default {
    data() {
      return {
        msg: 'hello Vue3',
        text: '你好 Vue3'
      }
    },
  }
</script>

<style scoped>
</style>

在这里插入图片描述

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值