首頁  >  文章  >  開發工具  >  vscode怎麼支援vue

vscode怎麼支援vue

尚
原創
2020-01-11 13:53:333508瀏覽

vscode怎麼支援vue

需要外掛程式: ESLint,Prettier - Code formatter,Vetur

開啟使用者設定檔:

// vscode默认启用了根据文件类型自动设置tabsize的选项
  "editor.detectIndentation": false,
  // 重新设定tabsize
  "editor.tabSize": 2,
  // #每次保存的时候自动格式化
  "editor.formatOnSave": true,
  //  #让函数(名)和后面的括号之间加个空格
  "javascript.format.insertSpaceBeforeFunctionParenthesis": true,
 
  //  #让prettier使用eslint的代码格式进行校验
  "prettier.eslintIntegration": true,
  //  #去掉代码结尾的分号
  "prettier.semi": false,
  //  #使用带引号替代双引号
  "prettier.singleQuote": true,
 
  // #每次保存的时候将代码按eslint格式进行修复
  "eslint.autoFixOnSave": true,
  // 添加 vue 支持
  "eslint.validate": [
    "javascript",
    "javascriptreact",
    {
      "language": "vue",
      "autoFix": true
    }
  ],
  
  // #这个按用户自身习惯选择
  "vetur.format.defaultFormatter.html": "js-beautify-html",
  "vetur.format.defaultFormatter.less": "prettier",
  "vetur.completion.autoImport": true,
  "vetur.format.defaultFormatter.js": "vscode-typescript",
  "vetur.format.defaultFormatterOptions": {
    "js-beautify-html": {
      "wrap_attributes": "force-aligned"
    }
  },

儲存程式碼自動依照eslint格式化。

斷點偵錯(需安裝Debugger for Chrome)

#1、在瀏覽器中展示原始碼如果你使用的是Vue CLI 2,請設定並更新config /index.js 內的devtool 屬性:

devtool: 'source-map',

如果你使用的是Vue CLI 3,請設定並更新vue.config.js 內的devtool 屬性:

module.exports = {
  configureWebpack: {
    devtool: 'source-map'
  }
}

2 、vscode中點選在Activity Bar 裡的Debugger 圖示來到Debug 視圖,然後點擊那個齒輪圖示來設定一個launch.json 的文件,選擇Chrome/Firefox: Launch 環境。然後將產生的 launch.json 的內容替換成為對應的配置:

{
  "version": "0.2.0",
  "configurations": [
    {
      "type": "chrome",
      "request": "launch",
      "name": "vuejs: chrome",
      "url": "http://localhost:8080",
      "webRoot": "${workspaceFolder}/src",
      "breakOnLoad": true,
      "sourceMapPathOverrides": {
        "webpack:///src/*": "${webRoot}/*"
      }
    },
    {
      "type": "firefox",
      "request": "launch",
      "name": "vuejs: firefox",
      "url": "http://localhost:8080",
      "webRoot": "${workspaceFolder}/src",
      "pathMappings": [{ "url": "webpack:///src/", "path": "${webRoot}/" }]
    }
  ]
}

推薦教學:vscode教學

以上是vscode怎麼支援vue的詳細內容。更多資訊請關注PHP中文網其他相關文章!

陳述:
本文內容由網友自願投稿,版權歸原作者所有。本站不承擔相應的法律責任。如發現涉嫌抄襲或侵權的內容,請聯絡admin@php.cn