Vue3在VSCod用步骤详解_Vetur_在搜索栏输入插件名称点击安装

Vue3在VSCode中的使用步骤详解


一、安装必要的扩展插件

为了在VSCode中使用Vue3,我们需要安装一些插件来增强开发体验。

安装步骤:

  1. 打开VSCode,点击左侧扩展图标(四个方块)。
  2. 在搜索栏输入插件名称,点击“安装”。

二、创建Vue3项目

首先,我们需要安装Vue CLI,然后创建一个新的Vue 3项目。

命令 说明
npm install -g @vue/cli 全局安装Vue CLI。
vue create my-vue3-project 创建一个新的Vue 3项目,命名为my-vue3-project。

在创建过程中,选择手动配置并选择Vue 3。

启动项目:进入项目目录,运行以下命令:

npm run serve

打开浏览器访问 http://localhost:8080,你将看到Vue的欢迎页面。

三、配置VSCode

设置ESLint和Prettier,配置VSCode的设置。

在项目根目录下创建或修改文件,配置ESLint和Prettier。

打开VSCode的设置,添加以下配置到用户或工作区设置中:

  "editor.formatOnSave": true,


  "editor.codeActionsOnSave": {


    "source.fixAll": true


  },


  "prettier.printWidth": 80,


  "prettier.tabWidth": 2

四、编写代码并运行项目

创建组件,例如在目录下创建一个名为MyComponent.vue的文件。

<template>


  <div>Hello Vue 3!</div>


</template>





<script>


export default {


  name: 'MyComponent'


}


</script>





<style scoped>


div {


  color: red;


}


</style>

在App.vue中使用组件:

<template>


  <div id="app">


    <my-component></my-component>


  </div>


</template>





<script>


import MyComponent from './components/MyComponent.vue'





export default {


  name: 'App',


  components: {


    MyComponent


  }


}


</script>

运行项目:在终端中运行以下命令启动开发服务器:

npm run serve

打开浏览器访问 http://localhost:8080,你将看到更新后的Vue应用。

你可以在VSCode中高效地使用Vue3进行开发。每一步都提供了详细的操作指南,确保你能够顺利完成开发环境的搭建和项目的启动。