vue3的使用

260 阅读1分钟

vue3的使用

创建vue3

  1. 创建vue3的指令
 vue create xxx
  1. 选择手动功能

333.png
3. 选择如下

456.png
4. 选择vue3的版本 666.png

ttt.png

qqq.png

ww.png

vue3生命周期函数

  1. setup() 页面创建之前执行的函数。所以整个面用setup()函数来初始化参数;
  2. onBeforeMount:页面渲染之前执行;onMounted: 页面渲染时;
  3. onBeforeUpdate:页面更新之前;onUpdated:页面更新之后;
  4. onBeforeUnmount:页面销毁之前;onUnmounted:页面销毁之后;

vue3升到vue3.2

  1. 升vue3.2的指令
npm i vue@3.2.8 vue-router@4.0.11 vuex@4.0.2
// yarn
yarn add vue@3.2.8 vue-router@4.0.11 vuex@4.0.2
  1. 升到vue3.2.8之后package.json的版本
    "vue": "3.2.8",
    "vue-router": "4.0.11",
    "vuex": "4.0.2"

Vue3.0 setup的使用

vue3.0在setup函数中定义的变量和方法最后都是需要 return 出去的 不然无法再模板中使用 vue3.0.png

Vue3.2 setup的使用

vue3.2 中 只需要在 script 标签上加上 setup 属性,无需return直接使用。

rrr.png

style中引用的方式

<template>
  <div class="box">hello linge</div>
</template>
 
<script setup>
import { ref } from 'vue'
const color = ref('red')
</script>
<style>
.box {
  width: 100px;
  height: 100px;
  color: v-bind(color);
}
</style>