VSCODE中使用Vue3教程

news/2024/7/16 8:24:04 标签: vscode, ide, vue.js, javascript

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.niftyadmin.cn/n/5393433.html

相关文章

Codeforces Round 927 G. Moving Platforms

原题链接&#xff1a;Problem - G - Codeforces 题目大意&#xff1a;有n个平台&#xff0c;m个通道&#xff0c;n个平台高度不一定相同&#xff0c;只有高度相同的时候才可以通过通道去下一个平台&#xff0c;通过通道时间为1秒&#xff0c;平台的高度每一秒都会增加&#xf…

谷歌搜索引擎关键词优化,竞价排名怎么做?大舍传媒

公司 大舍传媒成立于2005年&#xff0c;并从那时开始专注于谷歌搜索引擎优化&#xff08;SEO&#xff09;。如今&#xff0c;我们已经拥有了十八年的海外数字营销经验。我们为全球数千个国际知名品牌客户提供服务&#xff0c;是一家专注于技术的公司。 谷歌排名成果 在谷歌&…

kubectl命令以及yaml文件格式

目录 一、kubectl命令 二、yaml文件格式 三、写一个yaml文件demo 一、kubectl命令 //查看版本信息 kubectl version //查看资源对象简写 kubectl api-resources //查看集群信息 kubectl cluster-info //配置kubectl自动补全 source <(kubectl completion bash) …

数据安全之路:深入了解MySQL的行锁与表锁机制

欢迎来到我的博客&#xff0c;代码的世界里&#xff0c;每一行都是一个故事 数据安全之路&#xff1a;深入了解MySQL的行锁与表锁机制 前言基础innodb中锁与索引的关系如何避免表锁 前言 在当今数据密集的应用中&#xff0c;数据库锁成为了确保数据一致性和并发操作的关键工具…

如何在Linux搭建MinIO服务并实现无公网ip远程访问内网管理界面

文章目录 前言1. Docker 部署MinIO2. 本地访问MinIO3. Linux安装Cpolar4. 配置MinIO公网地址5. 远程访问MinIO管理界面6. 固定MinIO公网地址 前言 MinIO是一个开源的对象存储服务器&#xff0c;可以在各种环境中运行&#xff0c;例如本地、Docker容器、Kubernetes集群等。它兼…

华为OD机试真题-靠谱的车-2023年OD统一考试(C卷)---Python3-开源

题目&#xff1a; 考察内容&#xff1a; 思维转化&#xff0c;进制转化&#xff0c;9进制转为10进制&#xff0c;在4的位置1&#xff0c;需要判断是否大于4 代码&#xff1a; """ 题目分析&#xff1a; 9进制转化为10进制23-25 39-50 399-500输入&#xff1a…

ROS中简单实现讯飞星火大模型API调用

文章目录 前言一、申请试用二、ROS中使用1.配置环境变量2.编写ros功能包总结前言 讯飞星火认知大模型是由科大讯飞自主研发的认知智能大模型,通过学习海量的文本、代码和图像,具备跨领域的知识和语言理解能力,能基于自然对话方式理解和执行任务。目前开放了API接口供用户使…

邮件不只是文本:Focussend清晰用户画像,轻松拓展外贸市场!

在当今激烈的市场竞争中&#xff0c;吸引客户成为一项艰巨的任务。特别是在外贸业务中&#xff0c;成功的邮件营销策略变得尤为关键。本文将通过市场营销大环境、知识要点、共鸣情感和节奏感等多个维度&#xff0c;分享如何在外贸领域成功运用邮件营销&#xff0c;并结合 Focus…