1.点击设置=>用户代码片段
2.点击新建全局代码片段文件
3.创建json文件
4. 删除里面的东西
5.vue2和vue3自用代码片段
{
"vue2": {
"prefix": "vue2",
"body": [
"<template>",
" <div>\n",
" </div>",
"</template>\n",
"<script>",
"export default {",
" props: {\n",
" },",
" data() {",
" return {\n",
" };",
" },",
" methods: {\n",
" },",
" components: {\n",
" },",
"};",
"</script>\n",
"<style scoped lang=\"${1:less}\">\n",
"</style>\n",
],
"description": "Create vue template"
},
"vue3": {
"prefix": "vue3",
"body": [
"<template>",
" <div> </div>",
"</template>\n",
"<script lang='ts'>",
"import { defineComponent, onMounted, reactive, toRefs } from 'vue'",
"import { useRoute, useRouter } from 'vue-router'",
"import { useStore } from 'vuex'\n",
"export default defineComponent({",
" name: '自己命名',",
" components:{},",
" setup() {",
" const router = useRouter()",
" const route = useRoute()",
" const store = useStore()",
" const state = reactive({",
" // 进入页面加载,写在了onMounted中",
" onLoad: () => {",
" // ",
" }",
" })",
" onMounted(() => {",
" state.onLoad()",
" })",
" return {",
" ...toRefs(state)",
" }",
" }",
"})",
"</script>\n",
"<style scoped lang=\"${1:less}\">\n",
"</style>"
]
}
}
6.在新建页面输入vue2或vue3即可