安装node.js最新版

这里安装的是8.11.4

 
image.png

更新npm至最新版

安装node.js后, npm默认版本为: 6.1.0

 
image.png

使用npm install npm -g更新npm至最新版

 
image.png

安装vs code

安装过程就忽略了.

安装@vue/cli

> npm install -g @vue/cli

 
image.png

创建一个vue-demo-project工程

创建过程中默认配置(开箱即用)

 
image.png
 
image.png

打开工程

 
image.png

默认情况下, VS code是使用英文的, 有需要的话, 大家也可自行修改为中文:

  1. 按下ctrl+p, 输入: > Config, 选择: “Configure Display Language"

     
    image.png
  2. 将原先的:

     
    image.png

    修改为:

     
    image.png

修改并保存后, 会提示安装语言包, 安装即可:

打开一个.vue的文件时, 会提示推荐安装vetur插件, 当然选择安装了。安装成功后,会提示重启vscode

 
image.png

Vetur支持.vue文件的语法高亮显示,除了支持template模板以外,还支持大多数主流的前端开发脚本和插件,比如Sass和TypeScript等等

eslint

此时打开一个vue文件并编辑, 保存时并不会自动进行格式化, 这里还需要安装一些依赖和一些配置。

 
image.png

首先需要安装eslint

> npm install -g eslint

 
image.png

安装vscode 插件eslint

安装好vscode插件后, 执行vscode如下命令:

 
image.png

此时会在终端执行以下命令, 并按提示进行选择:

d:\Project\vue-demo-project>node_modules.bin\eslint.cmd --init
? How would you like to configure ESLint? Answer questions about your style
? Which version of ECMAScript do you use? ES2015
? Are you using ES6 modules? Yes
? Where will your code run? Browser
? Do you use CommonJS? Yes
? Do you use JSX? Yes
? Do you use React? Yes
? What style of indentation do you use? Tabs
? What quotes do you use for strings? Double
? What line endings do you use? Windows
? Do you require semicolons? No
? What format do you want your config file to be in? JSON
The config that you've selected requires the following dependencies:

eslint-plugin-react@latest
Successfully created .eslintrc.json file in d:\Project\vue-demo-project

d:\Project\vue-demo-project>

完成以上动作后, 会在当前工程目录下生成一个 .eslintrc.json文件

vs code中配置eslint保存时自动格式化

具体配置如下:

{
"files.autoSave": "off",
"files.autoSaveDelay": 1000,
"team.showWelcomeMessage": false,
"emmet.syntaxProfiles": {
"vue-html": "html",
"vue": "html"
}, "eslint.autoFixOnSave": true,
"eslint.validate": [
"javascript",{
"language": "vue",
"autoFix": true
},
"javascriptreact",
"html",
"vue"
],
"eslint.options": {
"plugins": ["html"]
},
//为了符合eslint的两个空格间隔原则
"editor.tabSize": 2,
"eslint.enable": true
}

eslint相关问题

1. eslint未生效

查看并检查下eslint server是否启动或报错

 
image.png

若有出错, 一般会给出提示, 按提示处理就好了。

2. 报错: Expected linebreaks to be 'CRLF' but found 'LF'. (linebreak-style)

有时会出现报错信息: Expected linebreaks to be 'CRLF' but found 'LF'. (linebreak-style)

不同的操作系统下,甚至是不同编辑器,不同工具处理过的文件可能都会导致换行符的改变。
如果实在找不出原因, 或者无法解决, 可以先关闭此项检测。

// 统一换行符,"\n" unix(for LF) and "\r\n" for windows(CRLF),默认unix
// off或0: 禁用规则
'linebreak-style': 'off'

3. 使用vue/cli 3.0 自定义配置项创建工程后, vscode中eslint无法自动修复格式的问题

原因: .eslintrc.js文件中缺少了配置, 如下图所示, 添加右侧红框部分后, 添加依赖eslint-plugin-html后即可.

 
image.png

附上.eslintrc.js详细备注

module.exports = {
// 默认情况下,ESLint会在所有父级组件中寻找配置文件,一直到根目录。ESLint一旦发现配置文件中有 "root": true,它就会停止在父级目录中寻找。
root: true,
// 对Babel解析器的包装使其与 ESLint 兼容。
parser: 'babel-eslint',
parserOptions: {
// 代码是 ECMAScript 模块
sourceType: 'module'
},
env: {
// 预定义的全局变量,这里是浏览器环境
browser: true,
},
// 扩展一个流行的风格指南,即 eslint-config-standard
// https://github.com/feross/standard/blob/master/RULES.md#javascript-standard-style
extends: 'standard',
// required to lint *.vue files
plugins: [
// 此插件用来识别.html 和 .vue文件中的js代码
'html',
// standard风格的依赖包
"standard",
// standard风格的依赖包
"promise"
],
//配置的一些规则
'rules': {
// allow paren-less arrow functions
'arrow-parens': 0,
// allow async-await
'generator-star-spacing': 0,
// allow debugger during development
'no-debugger': process.env.NODE_ENV === 'production' ? 2 : 0
}
}

最终的.eslintrc.json文件内容如下

{
"env": {
"browser": true,
"commonjs": true,
"es6": true
},
"extends": "eslint:recommended",
"parserOptions": {
"ecmaFeatures": {
"jsx": true
},
"ecmaVersion": 2018,
"sourceType": "module"
},
"plugins": [
"react"
],
"rules": {
"indent": [
"error",
"tab"
],
"linebreak-style": "off",
"quotes": [
"error",
"double"
],
"semi": [
"error",
"never"
]
}
}

基于Visual Studio Code搭建Vue开发环境的更多相关文章

  1. 使用Visual Studio Code搭建TypeScript开发环境

    使用Visual Studio Code搭建TypeScript开发环境 1.TypeScript是干什么的 ? TypeScript是由微软Anders Hejlsberg(安德斯·海尔斯伯格,也是 ...

  2. Windows下visual studio code搭建golang开发环境

    Windows下visual studio code搭建golang开发环境 序幕 其实环境搭建没什么难的,但是遇到一些问题,主要是有些网站资源访问不了(如:golang.org),导致一些包无法安装 ...

  3. 基于Visual Studio Code搭建Golang开发调试环境【非转载】

    由于对Docker+kubernetes的使用及持续关注,要理解这个平台的原理,势必需要对golang有一定的理解,基于此开始利用业余时间学习go,基础语法看完之后,搭建开发环境肯定是第一步,虽然能g ...

  4. Visual Studio Code 搭建Python开发环境

    1.下载Python https://www.python.org/downloads/windows/ 选择一个版本,目前2.0的源码比较多,我下载的2.7.12 2.配置环境变量 3.Visual ...

  5. Visual Studio Code搭建Python开发环境方法总结

    更新:目前VSCode官方Python插件已经支持代码运行与调试,无需安装Code Runner插件. 1.下载安装Python,地址 https://www.python.org/downloads ...

  6. Visual Studio Code搭建python开发环境

    开发Python的环境有很多,原来已经在vs2013上面搭建好python的开发环境了,但是vs2013每次启动都占太多内存(太强大了吧),这下出了vs code,既轻量又酷炫,正好拿来试一试开发py ...

  7. Windows10上基于Visual Studio Code安装Golang开发环境

    GoLang简介 Go编程语言是一个开源项目,它使程序员更具生产力. Go语言具有很强的表达能力,它简洁.清晰而高效.得益于其并发机制,用它编写的程序能够非常有效地利用多核与联网的计算机,其新颖的类型 ...

  8. visual studio 2015 搭建python开发环境,python入门到精通[三]

    在上一篇博客Windows搭建python开发环境,python入门到精通[一]很多园友提到希望使用visual studio 2013/visual studio 2015 python做demo, ...

  9. Windows系统 为 Visual Studio软件 搭建 OpenCV2 开发环境

    Windows系统 为 Visual Studio软件 搭建 OpenCV2 开发环境 我们的电脑系统:Windows 10 64位 Visual Studio 软件:Visual Studio 20 ...

随机推荐

  1. 系统空闲时间 解决 GetLastInputInfo 负数问题

    using System;using System.Collections.Generic;using System.Linq;using System.Runtime.InteropServices ...

  2. 49、[源码]-Spring容器创建-创建Bean准备

    49.[源码]-Spring容器创建-创建Bean准备

  3. 47、[源码]-Spring容器创建-初始化MessageSource

    47.[源码]-Spring容器创建-初始化MessageSource 7.initMessageSource();初始化MessageSource组件(做国际化功能:消息绑定,消息解析): 获取Be ...

  4. LeetCode 320. Generalized Abbreviation

    原题链接在这里:https://leetcode.com/problems/generalized-abbreviation/ 题目: Write a function to generate the ...

  5. GreenPlum 数据库启动关闭及数据库状态检查

    本篇文章主要记录GreenPlum数据库的启动.关闭及状态查询.GreenPlum数据库提供gpstart和gpstop脚本来启动和关闭数据库,可以通过—help参数来查看这些脚本的帮助信息. vie ...

  6. wepy小程序项目

    # 安装(更新) wepy 命令行工具. cnpm install wepy-cli -g # 安装依赖包 cnpm install # 开发实时编译. npm run dev WePY开发文档参考 ...

  7. 利用 Python 尝试采用面向对象的设计方法计算图形面积及周长

    利用 Python 尝试采用面向对象的设计方法.(1)设计一个基类 Shape:包含两个成员函数:def cal_area(): 计算并返回该图形的面积,保留两位小数:def cal_perimete ...

  8. 齿轮 HYSBZ - 4602 (DFS实现)

    齿轮 HYSBZ - 4602 题意:很好理解就不啰嗦了. 致谢:感谢队友小明. 题解:嗯,一开始想到的是并查集,后来,就先看了另一道题,xj写dfs和暴力,就卡死了.于是来补这题了,前向星建图 题解 ...

  9. ansible 主机正则

    ansible <pattern> -m <module_name> -a <arguments> 该功能主要针对Inventory的主机列表,案例如下: 1.AL ...

  10. 编程微语 2019-Autumn

    很多时候我们要的是[网页全屏],可是许多软件却做成了[浏览器全屏],不要一听到[全屏]就认为真的是传统意义上的全屏.拜托,老板(往往就是最大的产品经理).产品经理.程序员,想想,说清楚,做正确.某度文 ...