如何创建vue3项目

基于 vue 脚手架 npm i @vue/cli -g

vue create <project-name>
cd <project-name>
npm run serve

基于 vite 创建项目

// npm
npm init vite-app <project-name>
cd <project-name>
npm install
npm run dev
// yarn
yarn create vite-app <project-name>
cd <project-name>
yarn
yarn dev

vue3和vue2的区别

  • 模板组件结构

vue2中的组件模板必须要有唯一的根节点

vue3的组件模板可以没有根节点

  • 选项API 和 组合API

选项API:使用组件的选项(datacomputedmethodswatch)构建代码

优点:易于学习,这些选项规定了你变量方法该放在哪里

缺点:代码组织性差,当组件应用变的很大,逻辑关注的视图也会很长

组合API:以功能为单位,组织代码结构

源码优化

  • 数据响应式

vue2使用Object.defineproperty进行数据监听

vue3使用proxy进行数据监听

router4.x 和 router3.x的区别

  • 创建路由的方法

router3.x 使用 new Router创建路由

路由模式使用mode选项:mode: 'history' | 'hash'

import Router from 'vue-router'

const routes = [{
path: '/',
name: 'Home',
component: () => import('../views/home.vue')
}] const router = new Router({
mode: 'history',
routes
}) export default router

router4.x 使用 createRouter创建路由

路由模式使用函数方法:history: createWebHistory() | createWebHashHistory()

import {createRouter, createWebHashHistory, createWebHistory} from 'vue-router'

const routes = [{
path: '/',
name: 'Home',
component: () => import('../views/home.vue')
}] const router = createRouter({
history: createWebHashHistory(),
routes
}) export default router

组合式API相关方法

选项式 API Hook inside setup
beforeCreate Not needed*
created Not needed*
beforeMount onBeforeMount 挂载DOM前
mounted onMounted 挂载DOM后
beforeUpdate onBeforeUpdate更新前
updated onUpdated更新后
beforeUnmount onBeforeUnmount卸载销毁前
unmounted onUnmounted卸载销毁后
errorCaptured onErrorCaptured
renderTracked onRenderTracked
renderTriggered onRenderTriggered

vue3笔记的更多相关文章

  1. Vue3笔记(二)了解组合式API的应用与方法

    一.组合式API(Composition API)的介绍 官方文档: https://v3.cn.vuejs.org/guide/composition-api-introduction.html 组 ...

  2. 尤雨溪在直播中讲到的Vue3.0 Beta的那些特性,快记笔记了

    前言 在那天风雨交加的夜晚,Vue的创作者尤雨溪尤大大在b站直播分享了Vue.js 3.0 Beta最新进展.我对直播的内容进行了一下整理.整整用了三天的空余时间赶上了 1. 全新文档RFCs Vue ...

  3. vue3 学习笔记 (二)——axios 的使用有变化吗?

    本篇文章主要目的就是想告诉我身边,正在学 vue3 或者 准备学 vue3 的同学,vue3中网络请求axios该如何使用,防止接触了一点点 vue3 的同学会有个疑问?生命周期.router .vu ...

  4. vue3 学习笔记 (四)——vue3 setup() 高级用法

    本篇文章干货较多,建议收藏! 从 vue2 升级到 vue3,vue3 是可以兼容 vue2 的,所以 vue3 可以采用 vue2 的选项式API.由于选项式API一个变量存在于多处,如果出现问题时 ...

  5. vue 3 学习笔记 (七)——vue3 中 computed 新用法

    vue3 中 的 computed 的使用,由于 vue3 兼容 vue2 的选项式API,所以可以直接使用 vue2的写法,这篇文章主要介绍 vue3 中 computed 的新用法,对比 vue2 ...

  6. vue3 学习笔记(九)——script setup 语法糖用了才知道有多爽

    刚开始使用 script setup 语法糖的时候,编辑器会提示这是一个实验属性,要使用的话,需要固定 vue 版本. 在 6 月底,该提案被正式定稿,在 v3.1.3 的版本上,继续使用但仍会有实验 ...

  7. Vue3.x+element-plus+ts踩坑笔记

    闲聊 前段时间小颖在B站找了个学习vue3+TS的视频,自己尝试着搭建了一些基础代码,在实现功能的过程中遇到了一些问题,为了防止自己遗忘,写个随笔记录一下嘻嘻 项目代码 git地址:vue3.x-ts ...

  8. vue3的学习笔记:MVC、Vue3概要、模板、数据绑定、用Vue3 + element ui、react框架实现购物车案例

    一.前端MVC概要 1.1.库与框架的区别 框架是一个软件的半成品,在全局范围内给了大的约束.库是工具,在单点上给我们提供功能.框架是依赖库的.Vue是框架而jQuery则是库. 1.2.MVC(Mo ...

  9. vue3.0学习笔记

    vue3转vue2: https://vue-next-template-explorer.netlify.app/ 1. Vue3.0六大两点 Performance:性能比Vue2.x快1.2~2 ...

  10. Vue3学习笔记(1)

    安装 //使用yarn构建 //安装yarn 需要管理员权限 sudo npm i yarn -g yarn create vite cd .. yarn yarn dev 目录结构 见名知义 四种语 ...

随机推荐

  1. Brainstorm 了道题但是不会做

    题 因为没想出来暂时没定数据范围,不过应该会在 \(n^{2}\) 到 \(n^{3}\) 级别 我的一个思路是先对合法的方案连并查集,然后并查集内判重,但是不会算方案数,因为假如找到重的了不能直接看 ...

  2. C++指针等于地址加偏移量

    概述 本文通过c++示例代码演示指针的加减法运算及对 "指针 = 地址 + 偏移量" 的理解. 研究示例 1. 首先来检查各种变量类型所占的内存大小 #include <io ...

  3. 关于CycleGAN损失函数的可视化理解

    看了<Unpaired Image-to-Image Translation using Cycle-Consistent Adversarial Networks>这篇论文,大致了解了C ...

  4. .NET 实现的交互式 OA 系统

    前言 近期,我们在后台收到了粉丝们的留言,需要一个高效办公自动化(OA)系统.为了回应大家的期待,今天我们推荐一款既灵活又强大的 OA 系统解决方案,帮助提升日常办公效率和团队协作水平. 在日常工作中 ...

  5. Python:条件分支 if 语句全讲解

    Python:条件分支 if 语句全讲解 如果我拿出下面的代码,阁下该做何应对? if not reset_excuted and (terminated or truncated): ... els ...

  6. tmux从入门到装x

    原文: https://blog.csdn.net/CSSDCC/article/details/121231906 安装方法: # Ubuntu 或 Debian $ sudo apt-get in ...

  7. 在C#中基于Semantic Kernel的检索增强生成(RAG)实践

    Semantic Kernel简介 玩过大语言模型(LLM)的都知道OpenAI,然后微软Azure也提供了OpenAI的服务:Azure OpenAI,只需要申请到API Key,就可以使用这些AI ...

  8. SpringBoot2.0 整合 JWT 框架后台生成token

    一.传统Session认证 1.1.认证过程 1.用户向服务器发送用户名和密码.2.服务器验证后在当前对话(session)保存相关数据.3.服务器向返回sessionId,写入客户端 Cookie. ...

  9. 快速上手web前端开发(超详细教程)

    提示:文章写完后,目录可以自动生成,如何生成可参考右边的帮助文档 文章目录 前言 第一步 下安装vscode 第二步 vscode汉化 第三步 安装前端所需插件 1.Live Server 2.Jav ...

  10. Einfuehrung in die Kuenstliche Intelligenz学习笔记

    1.Uninformed Search 1.1 State Space of a Problem 1.2 depth of the search tree and fringe of the sear ...