当前位置: 首页 > news >正文

VSCODE中使用Vue3教程

VUE介绍

Vue.js is a popular JavaScript library for building web application user interfaces and Visual Studio Code has built-in support for the Vue.js building blocks of HTML, CSS, and JavaScript. For a richer Vue.js development environment, you can install the Volar and Volar for TypeScript extensions that support Vue.js IntelliSense, code snippets, formatting, and more.

Note: Vue 2 support will end on December 31st, 2023 so the use of the Vetur extension is not recommended. You will need to disable Vetur to use Volar.


welcome to Vue


本教程

本教程通过 Vite 工具创建项目Vue.js 框架官网:  vuejs.org website.

安装使用vue和vite之前需要先安装Node.js 和Npm. Node.js  npm (Node.js package manager) 官方下载,安装node时自动安装npm  Node.js downloads.

检查是否安装的命令  node --version and npm --version.

运行命令,如果没有安装Vue,则提示安装。

npm create vue@latest

Create vue

安装后的界面如下,尽量选择No。最小化安装过程。

Vue app scaffolding

按照提示, 到对应项目目录中。执行 npm install.  npm run dev命令执行项目。在

cd <your-project-name>
npm install

npm run dev

 浏览器输入 http://localhost:5173 显示如下:

welcome to Vue

打开VSCODE的方式,自动进入项目:

cd vue-project
code .

Volar extension 安装扩展

 系统建议安装扩展volar,选择install即可。

Volar extension recommendation

Volar界面如下

Volar extension

安装后,.vue文件显示。

Vue language features

IntelliSense智能代码补全

As you start typing in App.vue, you'll see smart suggestions or completions both for HTML and CSS but also for Vue.js specific items like declarations (v-bindv-for) in the Vue template section:

Vue.js suggestions

and Vue properties such as computed in the scripts section:

Vue.js JavaScript suggestions

Go to Definition, Peek definition 查看定义和源代码功能

VS Code through the Volar extension Vue.js language service can also provide type definition information in the editor through Go to Definition (F12) or Peek Definition (Alt+F12). Put the cursor over the App, right-click and select Peek Definition. A Peek window opens showing the App definition from App.js.

Vue.js peek definition

Press Escape to close the Peek window.

Hello World 最小变化

Let's update the sample application to "Hello World!". In App.vue replace the HelloWorld component msg custom attribute text with "Hello World!".

<template><header><img alt="Vue logo" class="logo" src="./assets/logo.svg" width="125" height="125" /><div class="wrapper"><HelloWorld msg="Hello World!" /></div></header><main><TheWelcome /></main>
</template>

Once you save the App.vue file (Ctrl+S), restart the server with npm run dev and you'll see "Hello World!". Leave the server running while we go on to learn about Vue.js client side debugging.

Tip: VS Code supports Auto Save, which by default saves your files after a delay. Check the Auto Save option in the File menu to turn on Auto Save or directly configure the files.autoSave user setting.


hello world


Linting语法纠错

Linters analyze your source code and can warn you about potential problems before you run your application. The Vue ESLint plugin (eslint-plugin-vue) checks for Vue.js specific syntax errors, which are shown in the editor as red squiggles and are also displayed in the Problems panel (View > Problems Ctrl+Shift+M).

Below you can see an error when the Vue linter detects more than one root element in a template:

Vue linting

Debugging调试工具

You can debug client side Vue.js code with the built-in JavaScript debugger. Follow this conversation to use Vite/Vue.js 3 project with VS Code using Microsoft Edge.

For Vue CLI, which is now in maintenance mode, check out Vue.js debugging in VS Code recipe on the VS Code debugging recipes site to learn more.

Another popular tool for debugging Vue.js is the vue-devtools plug-in, which can be used regardless of the environment.

Other extensions 其他扩展

VScode会建议安装扩展。Volar is only one of many Vue.js extensions available for VS Code. Another recommended extension is Volar for TypeScript.

Vue recommended extensions

You can search in the Extensions view (Ctrl+Shift+X) by typing 'vue'.

Vue.js extensions

Extension like Vue VS Code Snippets can be handy for Vue snippets. 代码片段(类似宏的功能)

Vue VS Code Snippets

There are also Extension Packs, which bundle extensions that other people have found useful for Vue.js development.

Vue.js Extension Pack

http://www.lryc.cn/news/304123.html

相关文章:

  • Mac M2芯片配置PHP环境
  • [嵌入式系统-25]:RT-Thread -12- 内核组件编程接口 - 网络组件 - HTTP编程
  • 一个服务器实现本机服务互联网化
  • django配置视图并与模版进行数据交互
  • Java进阶
  • ⭐北邮复试刷题106. 从中序与后序遍历序列构造二叉树__递归分治 (力扣每日一题)
  • K8S更新部署docker的两种方法举例
  • Java高并发编程基础之Thread构造函数大有内涵
  • 2023年12月 Python(六级)真题解析#中国电子学会#全国青少年软件编程等级考试
  • 代码随想录算法训练营第一天
  • 基于 java springboot+layui仓库管理系统
  • 电商平台商家结算
  • AIGC 实战:如何使用 Docker 在 Ollama 上离线运行大模型(LLM)
  • MII、RMII、GMII和RGMII,以太网接口中常见的几种标准接口
  • SpringCloudConfig+SpringCloudBus+Actuator+Git实现Eureka关键配置属性热更新(全程不重启服务)
  • 郑州大学2024年寒假训练 Day7:数论
  • “目标检测”任务基础认识
  • springboot+vue的宠物咖啡馆平台(前后端分离)
  • LaWGPT—基于中文法律知识的大模型
  • 一文弄明白KeyedProcessFunction函数
  • alibabacloud学习笔记06(小滴课堂)
  • Code Composer Studio (CCS) - Licensing Information
  • uniapp引入微信小程序直播组件
  • 五个简单的C#编程案例
  • Zlibrary低调官宣2024年最新网址,国内可直接访问,免费下载海量电子书籍
  • Android 开机启动
  • 二叉树相关算法需了解汇总-基础算法操作
  • 万字干货-京东零售数据资产能力升级与实践
  • 探索前端框架的世界:一场前端之旅
  • class complex