1. 安裝vscode
vscode下載地址:https://code.visualstudio.com
2. 安裝Vetur插件
插件庫中搜索Vetur,下圖中的第一個,點擊安裝,安裝完成之後點擊重新加載
3. 新建代碼片段
文件–>首選項–>用戶代碼片段–>點擊新建代碼片段–取名vue.json 確定
4.刪除不要的代碼,粘入.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"
}
}