【vsCode】識別.vue/一鍵生成.vue模板文件


1.安裝插件Vetur     

 

 結果 ---> .vue代碼識別彩標

2.配置.vue文件模板,以便快速一鍵生成格式化

   2.1新建代碼片段

   File->Preferences->User Snippets-->New Global Snippets file... -->取名vue.json

   2.2刪除其中的代碼片段
   2.3黏貼.vue配置代碼
{
    "Print to console": {
        "prefix": "vue",
        "body": [
            "<!-- $1 -->",
            "<template>",
            "<div class='$2'>$5</div>",
            "</template>",
            "",
            "<script>",
            "//這里可以導入其他文件(比如:組件,工具js,第三方插件js,json文件,圖片文件等等)",
            "//例如:import 《組件名稱》 from '《組件路徑》';",
            "",
            "export default {",
            "//import引入的組件需要注入到對象中才能使用",
            "components: {},",
            "data() {",
            "//這里存放數據",
            "return {",
            "",
            "};",
            "},",
            "//監聽屬性 類似於data概念",
            "computed: {},",
            "//監控data中的數據變化",
            "watch: {},",
            "//方法集合",
            "methods: {",
            "",
            "},",
            "//生命周期 - 創建完成(可以訪問當前this實例)",
            "created() {",
            "",
            "},",
            "//生命周期 - 掛載完成(可以訪問DOM元素)",
            "mounted() {",
            "",
            "},",
            "beforeCreate() {}, //生命周期 - 創建之前",
            "beforeMount() {}, //生命周期 - 掛載之前",
            "beforeUpdate() {}, //生命周期 - 更新之前",
            "updated() {}, //生命周期 - 更新之后",
            "beforeDestroy() {}, //生命周期 - 銷毀之前",
            "destroyed() {}, //生命周期 - 銷毀完成",
            "activated() {}, //如果頁面有keep-alive緩存功能,這個函數會觸發",
            "}",
            "</script>",
            "<style lang='scss' scoped>",
            "//@import url($3); 引入公共css類",
            "$4",
            "</style>"
        ],
        "description": "Log output to console"
    }
}
View Code

 結果 --->保存好之后,新建.vue結尾的文件,在文件中輸入vue並按下Tab鍵,則一鍵生成同模板的.vue文件代碼段

3.根據eslint保存自動修復配置

  3.1安裝插件eslint和prettier
  3.2配置settings

 File->Preferences->Settings -->黏貼設置代碼

{
  "editor.formatOnPaste": true, //粘貼時格式化
  "eslint.autoFixOnSave": true /**eslint保存自動校驗不全*/,
  "eslint.alwaysShowStatus": true,
  "eslint.validate": [
    "javascript",
    "javascriptreact",
    {
      "language": "html",
      "autoFix": true
    },
    {
      "language": "vue",
      "autoFix": true
    }
  ],
  // "window.zoomLevel": 1, // 窗口大小比例
  // "editor.tabSize": 2,
  "editor.detectIndentation": false,
  "emmet.triggerExpansionOnTab": true,
  // "update.channel": "none",
  "editor.formatOnSave": true, // eslint保存格式化
  "javascript.format.enable": false // 不啟動JavaScript格式化
  // "prettier.eslintIntegration": true // 讓prettier遵循eslint格式美化
}
View Code

 

 

   

   


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM