vscode 自定義vue 開發(fā)模板

需求背景:
提高開發(fā)效率,靈活使用vscode開發(fā)工具

方法步驟:

  1. 打開vue模板的配置文件vue.json
文件-->首選項-->用戶代碼片段-->點擊新建代碼片段--取名vue.json 確定

2.配置相關(guān)文件

{
    // Place your snippets for vue here. Each snippet is defined under a snippet name and has a prefix, body and 
    // description. The prefix is what is used to trigger the snippet and the body will be expanded and inserted. Possible variables are:
    // $1, $2 for tab stops, $0 for the final cursor position, and ${1:label}, ${2:another} for placeholders. Placeholders with the 
    // same ids are connected.
    // Example:
    // "Print to console": {
    //  "prefix": "log",
    //  "body": [
    //      "console.log('$1');",
    //      "$2"
    //  ],
    //  "description": "Log output to console"
    // }
    "Print to console": {
        "prefix": "vue",
        "body": [
            "<!-- $1 -->",
            "<template>",
            "<div class='container-wrapper'>$5</div>",
            "</template>",
            "",
            "<script>",
            "http://這里可以導(dǎo)入其他文件(比如:組件,工具js,第三方插件js,json文件,圖片文件等等)",
            "http://例如:import 《組件名稱》 from '《組件路徑》';",
            "",
            "export default {",
            "  name: \"${1:component-name}\",",
            "http://import引入的組件需要注入到對象中才能使用",
            "components: {},",
            "data() {",
            "http://這里存放數(shù)據(jù)",
            "return {",
            "",
            "};",
            "},",
            "http://監(jiān)聽屬性 類似于data概念",
            "computed: {},",
            "http://監(jiān)控data中的數(shù)據(jù)變化",
            "watch: {},",
            "http://生命周期 - 創(chuàng)建完成(可以訪問當前this實例)",
            "created() {",
            "",
            "},",
            "http://生命周期 - 掛載完成(可以訪問DOM元素)",
            "mounted() {",
            "",
            "},",
            "beforeCreate() {}, //生命周期 - 創(chuàng)建之前",
            "beforeMount() {}, //生命周期 - 掛載之前",
            "beforeUpdate() {}, //生命周期 - 更新之前",
            "updated() {}, //生命周期 - 更新之后",
            "beforeDestroy() {}, //生命周期 - 銷毀之前",
            "destroyed() {}, //生命周期 - 銷毀完成",
            "activated() {}, //如果頁面有keep-alive緩存功能,這個函數(shù)會觸發(fā)",
            "http://方法集合",
            "methods: {",
            "",
            "},",
            "}",
            "</script>",
            "<style lang='less' scoped>",
            "http://@import url($3); 引入公共css類",
            "$4",
            "</style>"
        ],
        "description": "Log output to console"
    }
}

注:上面代碼中的 "prefix": "vue", 就是快捷鍵;保存好之后,可以通過新建.vue結(jié)尾的文件驗證

3.效果展示
實際配置因以具體項目,實際需求為主


vue-template.png

比如這樣的一個簡約配置:


vue-template2.png

其他開發(fā)模板,如在vscode下的react開發(fā)模板也是類似的。

?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時請結(jié)合常識與多方信息審慎甄別。
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點,簡書系信息發(fā)布平臺,僅提供信息存儲服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容