选择菜单里的 文件 > 首选项 > 用户代码片段
vscode模板
{
"Print to conaole":{
"prefix": "v-ts", //在新建立的页面中输入C++就会有智能提示,Tab就自动生成好了
"body": [
"<template>",
" <div class='con'>", //这个头文件可以删除,我为了使用方便就加了
" <header></header>",
" <section></section>",
" </div>", //空行
"</template>", //标准命名空间
"<script lang='ts' setup>",
"/** 接口 */", //main()函数
"export interface propsForm {",
"}",
"import { reactive, toRefs, defineProps, withDefaults, defineEmits, ref, computed } from 'vue';",
"import useCurrentInstance from '@/api/useCurrentInstance';",
"const { proxy } = useCurrentInstance()",
"const emit = defineEmits(['searchFunction'])",
"/** prop */",
"const props = withDefaults(defineProps<propsForm>(), {",
"})",
"/** 计算属性*/",
"const xx = computed(() => [])",
"/** data */", //最终光标会在这里等待输入
"const state = reactive({",
"})",
"const { searchForm } = toRefs(state)",
"/** 监听 */", //标准C++的等待用户动作
"/** 生命周期 */", //结束
"/** methods */",
"/** 接口 */",
"</script>",
"<style>",
"</style>"
],
"description": "vue3 template." //用户输入后智能提示的内容(你可以用中文写“生成C++模板”)
}
}
结果文章来源:https://www.toymoban.com/news/detail-725497.html
<template>
<div class='con'>
<header></header>
<section></section>
</div>
</template>
<script lang='ts' setup>
/** 接口 */
export interface propsForm {
}
import { reactive, toRefs, defineProps, withDefaults, defineEmits, ref, computed } from 'vue';
import useCurrentInstance from '@/api/useCurrentInstance';
const { proxy } = useCurrentInstance()
const emit = defineEmits(['searchFunction'])
/** prop */
const props = withDefaults(defineProps<propsForm>(), {
})
/** 计算属性*/
const xx = computed(() => [])
/** data */
const state = reactive({
})
const { searchForm } = toRefs(state)
/** 监听 */
/** 生命周期 */
/** methods */
/** 接口 */
</script>
<style>
</style>
useCurrentInstance.ts文章来源地址https://www.toymoban.com/news/detail-725497.html
import { ComponentInternalInstance, getCurrentInstance } from 'vue'
// eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types
export default function useCurrentInstance() {
const { appContext } = getCurrentInstance() as ComponentInternalInstance
const proxy = appContext.config.globalProperties
return {
proxy
}
}
到了这里,关于vue3模板-vscode设置(语法糖)的文章就介绍完了。如果您还想了解更多内容,请在右上角搜索TOY模板网以前的文章或继续浏览下面的相关文章,希望大家以后多多支持TOY模板网!