需求背景:
提高開發(fā)效率,靈活使用vscode開發(fā)工具
方法步驟:
- 打開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ā)模板也是類似的。