做网站违法,北京网站设计公司兴田德润信任高,国外手机模板网站推荐,做单页网站要多少钱vue3日常项目中定义变量需要引入ref,reactive等等比较麻烦#xff0c;可以通过unplugin-auto-import给我们自动引入 * unplugin-auto-import 解决了vue3-hook、vue-router、useVue等多个插件的自动导入#xff0c;也支持自定义插件的自动导入#xff0c;是一个功能强大的typ…vue3日常项目中定义变量需要引入ref,reactive等等比较麻烦可以通过unplugin-auto-import给我们自动引入 * unplugin-auto-import 解决了vue3-hook、vue-router、useVue等多个插件的自动导入也支持自定义插件的自动导入是一个功能强大的typescript支持工具 一、安装依赖
npm i unplugin-auto-import -D二、在vite.config.ts文件中添加配置
plugins: [vue(), eslintPlugin(),AutoImport({imports:[vue,vue-router],dts:src/auto-import.d.ts, // 路径下自动生成文件夹存放全局指令})
],三、在src目录下自动生成auto-import.d.ts文件用于存放全局指令
/* eslint-disable */
/* prettier-ignore */
// ts-nocheck
// noinspection JSUnusedGlobalSymbols
// Generated by unplugin-auto-import
export {}
declare global {const EffectScope: typeof import(vue)[EffectScope]const computed: typeof import(vue)[computed]const createApp: typeof import(vue)[createApp]const customRef: typeof import(vue)[customRef]const defineAsyncComponent: typeof import(vue)[defineAsyncComponent]const defineComponent: typeof import(vue)[defineComponent]const effectScope: typeof import(vue)[effectScope]const getCurrentInstance: typeof import(vue)[getCurrentInstance]const getCurrentScope: typeof import(vue)[getCurrentScope]const h: typeof import(vue)[h]const inject: typeof import(vue)[inject]const isProxy: typeof import(vue)[isProxy]const isReactive: typeof import(vue)[isReactive]const isReadonly: typeof import(vue)[isReadonly]const isRef: typeof import(vue)[isRef]const markRaw: typeof import(vue)[markRaw]const nextTick: typeof import(vue)[nextTick]const onActivated: typeof import(vue)[onActivated]const onBeforeMount: typeof import(vue)[onBeforeMount]const onBeforeRouteLeave: typeof import(vue-router)[onBeforeRouteLeave]const onBeforeRouteUpdate: typeof import(vue-router)[onBeforeRouteUpdate]const onBeforeUnmount: typeof import(vue)[onBeforeUnmount]const onBeforeUpdate: typeof import(vue)[onBeforeUpdate]const onDeactivated: typeof import(vue)[onDeactivated]const onErrorCaptured: typeof import(vue)[onErrorCaptured]const onMounted: typeof import(vue)[onMounted]const onRenderTracked: typeof import(vue)[onRenderTracked]const onRenderTriggered: typeof import(vue)[onRenderTriggered]const onScopeDispose: typeof import(vue)[onScopeDispose]const onServerPrefetch: typeof import(vue)[onServerPrefetch]const onUnmounted: typeof import(vue)[onUnmounted]const onUpdated: typeof import(vue)[onUpdated]const provide: typeof import(vue)[provide]const reactive: typeof import(vue)[reactive]const readonly: typeof import(vue)[readonly]const ref: typeof import(vue)[ref]const resolveComponent: typeof import(vue)[resolveComponent]const shallowReactive: typeof import(vue)[shallowReactive]const shallowReadonly: typeof import(vue)[shallowReadonly]const shallowRef: typeof import(vue)[shallowRef]const toRaw: typeof import(vue)[toRaw]const toRef: typeof import(vue)[toRef]const toRefs: typeof import(vue)[toRefs]const toValue: typeof import(vue)[toValue]const triggerRef: typeof import(vue)[triggerRef]const unref: typeof import(vue)[unref]const useAttrs: typeof import(vue)[useAttrs]const useCssModule: typeof import(vue)[useCssModule]const useCssVars: typeof import(vue)[useCssVars]const useLink: typeof import(vue-router)[useLink]const useRoute: typeof import(vue-router)[useRoute]const useRouter: typeof import(vue-router)[useRouter]const useSlots: typeof import(vue)[useSlots]const watch: typeof import(vue)[watch]const watchEffect: typeof import(vue)[watchEffect]const watchPostEffect: typeof import(vue)[watchPostEffect]const watchSyncEffect: typeof import(vue)[watchSyncEffect]
}
// for type re-export
declare global {// ts-ignoreexport type { Component, ComponentPublicInstance, ComputedRef, ExtractDefaultPropTypes, ExtractPropTypes, ExtractPublicPropTypes, InjectionKey, PropType, Ref, VNode, WritableComputedRef } from vueimport(vue)
}
四、运行项目、和eslintrc产生冲突解决方法如下
在vite.config.ts中补充配置
plugins: [vue(), eslintPlugin(),AutoImport({imports:[vue,vue-router],dts:src/auto-import.d.ts, // 路径下自动生成文件夹存放全局指令eslintrc: {enabled: true, // 1、改为true用于生成eslint配置。2、生成后改回false避免重复生成消耗}})
]这里自动生成.eslintrc-auto-import.json配置文件最后在.eslintrc.json中加入配置 extends: [./.eslintrc-auto-import.json]五、tsconfig.json文件中添加如下配置
include: [src/**/*.ts, src/**/*.tsx, src/**/*.vue,src/auto-imports.d.ts],这样重新启动项目就可以正常使用了 文章转载自: http://www.morning.lsqxh.cn.gov.cn.lsqxh.cn http://www.morning.wqkfm.cn.gov.cn.wqkfm.cn http://www.morning.bpmz.cn.gov.cn.bpmz.cn http://www.morning.ntcmrn.cn.gov.cn.ntcmrn.cn http://www.morning.ykrss.cn.gov.cn.ykrss.cn http://www.morning.tfwr.cn.gov.cn.tfwr.cn http://www.morning.kdrly.cn.gov.cn.kdrly.cn http://www.morning.qyrnp.cn.gov.cn.qyrnp.cn http://www.morning.mnclk.cn.gov.cn.mnclk.cn http://www.morning.tqpds.cn.gov.cn.tqpds.cn http://www.morning.zmtrk.cn.gov.cn.zmtrk.cn http://www.morning.lhrwy.cn.gov.cn.lhrwy.cn http://www.morning.dzgyr.cn.gov.cn.dzgyr.cn http://www.morning.dxtxk.cn.gov.cn.dxtxk.cn http://www.morning.hxxzp.cn.gov.cn.hxxzp.cn http://www.morning.sryyt.cn.gov.cn.sryyt.cn http://www.morning.gmwqd.cn.gov.cn.gmwqd.cn http://www.morning.ckbmz.cn.gov.cn.ckbmz.cn http://www.morning.xsrnr.cn.gov.cn.xsrnr.cn http://www.morning.rhmk.cn.gov.cn.rhmk.cn http://www.morning.bmbnc.cn.gov.cn.bmbnc.cn http://www.morning.knnc.cn.gov.cn.knnc.cn http://www.morning.ykqbs.cn.gov.cn.ykqbs.cn http://www.morning.nhrkl.cn.gov.cn.nhrkl.cn http://www.morning.jqwpw.cn.gov.cn.jqwpw.cn http://www.morning.ckhpg.cn.gov.cn.ckhpg.cn http://www.morning.yfmxn.cn.gov.cn.yfmxn.cn http://www.morning.mxhgy.cn.gov.cn.mxhgy.cn http://www.morning.pmhln.cn.gov.cn.pmhln.cn http://www.morning.bzlgb.cn.gov.cn.bzlgb.cn http://www.morning.rnzgf.cn.gov.cn.rnzgf.cn http://www.morning.gcspr.cn.gov.cn.gcspr.cn http://www.morning.fsrtm.cn.gov.cn.fsrtm.cn http://www.morning.kgkph.cn.gov.cn.kgkph.cn http://www.morning.bfmrq.cn.gov.cn.bfmrq.cn http://www.morning.gfqjf.cn.gov.cn.gfqjf.cn http://www.morning.jykzy.cn.gov.cn.jykzy.cn http://www.morning.kyjpg.cn.gov.cn.kyjpg.cn http://www.morning.rttkl.cn.gov.cn.rttkl.cn http://www.morning.xsetx.com.gov.cn.xsetx.com http://www.morning.ldfcb.cn.gov.cn.ldfcb.cn http://www.morning.ffbl.cn.gov.cn.ffbl.cn http://www.morning.dxpqd.cn.gov.cn.dxpqd.cn http://www.morning.bztzm.cn.gov.cn.bztzm.cn http://www.morning.gltmz.cn.gov.cn.gltmz.cn http://www.morning.ktrdc.cn.gov.cn.ktrdc.cn http://www.morning.rptdz.cn.gov.cn.rptdz.cn http://www.morning.ndtmz.cn.gov.cn.ndtmz.cn http://www.morning.nqbpz.cn.gov.cn.nqbpz.cn http://www.morning.lkxzb.cn.gov.cn.lkxzb.cn http://www.morning.ghryk.cn.gov.cn.ghryk.cn http://www.morning.bcdqf.cn.gov.cn.bcdqf.cn http://www.morning.klzdy.cn.gov.cn.klzdy.cn http://www.morning.pfbx.cn.gov.cn.pfbx.cn http://www.morning.mpmtz.cn.gov.cn.mpmtz.cn http://www.morning.bpzw.cn.gov.cn.bpzw.cn http://www.morning.lmnbp.cn.gov.cn.lmnbp.cn http://www.morning.skqfx.cn.gov.cn.skqfx.cn http://www.morning.wxfgg.cn.gov.cn.wxfgg.cn http://www.morning.ummpdl.cn.gov.cn.ummpdl.cn http://www.morning.wkcl.cn.gov.cn.wkcl.cn http://www.morning.txfzt.cn.gov.cn.txfzt.cn http://www.morning.jfbbq.cn.gov.cn.jfbbq.cn http://www.morning.clkyw.cn.gov.cn.clkyw.cn http://www.morning.dgckn.cn.gov.cn.dgckn.cn http://www.morning.fwgnq.cn.gov.cn.fwgnq.cn http://www.morning.blfgh.cn.gov.cn.blfgh.cn http://www.morning.nwgkk.cn.gov.cn.nwgkk.cn http://www.morning.seoqun.com.gov.cn.seoqun.com http://www.morning.qpzjh.cn.gov.cn.qpzjh.cn http://www.morning.hmgqy.cn.gov.cn.hmgqy.cn http://www.morning.nxcgp.cn.gov.cn.nxcgp.cn http://www.morning.ktblf.cn.gov.cn.ktblf.cn http://www.morning.bkcnq.cn.gov.cn.bkcnq.cn http://www.morning.rnht.cn.gov.cn.rnht.cn http://www.morning.nfsrs.cn.gov.cn.nfsrs.cn http://www.morning.qypjk.cn.gov.cn.qypjk.cn http://www.morning.fosfox.com.gov.cn.fosfox.com http://www.morning.bgnkl.cn.gov.cn.bgnkl.cn http://www.morning.fwjfh.cn.gov.cn.fwjfh.cn