首先在vscode中 使用快捷键ctrl+shift+p快捷键
    image.png
    然后点击首选项
    image.png
    点击新建全局代码片段文件
    image.png
    然后在输入文件名保存,比如输入vue

    1. {
    2. // Place your 全局 snippets here. Each snippet is defined under a snippet name and has a scope, prefix, body and
    3. // description. Add comma separated ids of the languages where the snippet is applicable in the scope field. If scope
    4. // is left empty or omitted, the snippet gets applied to all languages. The prefix is what is
    5. // used to trigger the snippet and the body will be expanded and inserted. Possible variables are:
    6. // $1, $2 for tab stops, $0 for the final cursor position, and ${1:label}, ${2:another} for placeholders.
    7. // Placeholders with the same ids are connected.
    8. // Example:
    9. // "Print to console": {
    10. // "scope": "javascript,typescript",
    11. // "prefix": "log",
    12. // "body": [
    13. // "console.log('$1');",
    14. // "$2"
    15. // ],
    16. // "description": "Log output to console"
    17. // }
    18. }

    这是初始化代码,然后在Example:下面添加你初始化的代码即可。

    1. "Print to console": {
    2. "prefix": "vue",
    3. "body": [
    4. "<template>",
    5. " <div>",
    6. " </div>",
    7. "</template>",
    8. "",
    9. "<script>",
    10. " export default {",
    11. " data() {",
    12. " return {",
    13. "",
    14. " };",
    15. " },",
    16. " created() {",
    17. "",
    18. " },",
    19. " mounted() {",
    20. "",
    21. " },",
    22. " methods: {",
    23. "",
    24. " },",
    25. "}",
    26. "</script>",
    27. "",
    28. "<style lang='scss' scoped>",
    29. "$4",
    30. "</style>"
    31. ],
    32. "description": "Log output to console"
    33. }

    最后在你想要添加vue文件中,输入vue点击table键即可,就可以自动生成你初始化的模板代码了。
    参考文章:

    1. vscode vue添加代码片段