当前位置:   article > 正文

vue3+vite中再也不用单独页面引入vue了,神器:unplugin-vue-components/vite_plugin: vite-plugin-eslint file: e:/boke/vue3-proj

plugin: vite-plugin-eslint file: e:/boke/vue3-project/src/main.ts

前言:

        你是否还在为vue3项目中每个组件都需要单独引入vue而烦恼着,实际vite有一个插件能很好的解决这个问题,那就是 unplugin-auto-import/vite

使用步骤:

1、安装 npm/cnpm/pnpm/yarn  都可以,装上下面两个插件

unplugin-auto-import/vite

2、vite.config.js中配置

  1. import AutoImport from 'unplugin-auto-import/vite';// 自动导入vue中hook reactive ref
  2. const config = {
  3. plugins: [
  4. AutoImport({
  5. //安装两行后你会发现在组件中不用再导入ref,reactive等
  6. imports: ['vue', 'vue-router','@vueuse/core'],
  7. //存放的位置
  8. dts: 'src/types/auto-import.d.ts',
  9. }),
  10. ]
  11. }

3、页面上试试,发现是可以的

4、types下的auto-import.d.ts,自动生成

  1. /* eslint-disable */
  2. /* prettier-ignore */
  3. // @ts-nocheck
  4. // noinspection JSUnusedGlobalSymbols
  5. // Generated by unplugin-auto-import
  6. export {}
  7. declare global {
  8. const EffectScope: typeof import('vue')['EffectScope']
  9. const asyncComputed: typeof import('@vueuse/core')['asyncComputed']
  10. const autoResetRef: typeof import('@vueuse/core')['autoResetRef']
  11. const computed: typeof import('vue')['computed']
  12. const computedAsync: typeof import('@vueuse/core')['computedAsync']
  13. const computedEager: typeof import('@vueuse/core')['computedEager']
  14. const computedInject: typeof import('@vueuse/core')['computedInject']
  15. const computedWithControl: typeof import('@vueuse/core')['computedWithControl']
  16. const controlledComputed: typeof import('@vueuse/core')['controlledComputed']
  17. const controlledRef: typeof import('@vueuse/core')['controlledRef']
  18. const createApp: typeof import('vue')['createApp']
  19. const createEventHook: typeof import('@vueuse/core')['createEventHook']
  20. const createGlobalState: typeof import('@vueuse/core')['createGlobalState']
  21. const createInjectionState: typeof import('@vueuse/core')['createInjectionState']
  22. const createReactiveFn: typeof import('@vueuse/core')['createReactiveFn']
  23. const createSharedComposable: typeof import('@vueuse/core')['createSharedComposable']
  24. const createUnrefFn: typeof import('@vueuse/core')['createUnrefFn']
  25. const customRef: typeof import('vue')['customRef']
  26. const debouncedRef: typeof import('@vueuse/core')['debouncedRef']
  27. const debouncedWatch: typeof import('@vueuse/core')['debouncedWatch']
  28. const defineAsyncComponent: typeof import('vue')['defineAsyncComponent']
  29. const defineComponent: typeof import('vue')['defineComponent']
  30. const eagerComputed: typeof import('@vueuse/core')['eagerComputed']
  31. const effectScope: typeof import('vue')['effectScope']
  32. const extendRef: typeof import('@vueuse/core')['extendRef']
  33. const getCurrentInstance: typeof import('vue')['getCurrentInstance']
  34. const getCurrentScope: typeof import('vue')['getCurrentScope']
  35. const h: typeof import('vue')['h']
  36. const ignorableWatch: typeof import('@vueuse/core')['ignorableWatch']
  37. const inject: typeof import('vue')['inject']
  38. const isDefined: typeof import('@vueuse/core')['isDefined']
  39. const isProxy: typeof import('vue')['isProxy']
  40. const isReactive: typeof import('vue')['isReactive']
  41. const isReadonly: typeof import('vue')['isReadonly']
  42. const isRef: typeof import('vue')['isRef']
  43. const makeDestructurable: typeof import('@vueuse/core')['makeDestructurable']
  44. const markRaw: typeof import('vue')['markRaw']
  45. const nextTick: typeof import('vue')['nextTick']
  46. const onActivated: typeof import('vue')['onActivated']
  47. const onBeforeMount: typeof import('vue')['onBeforeMount']
  48. const onBeforeRouteLeave: typeof import('vue-router')['onBeforeRouteLeave']
  49. const onBeforeRouteUpdate: typeof import('vue-router')['onBeforeRouteUpdate']
  50. const onBeforeUnmount: typeof import('vue')['onBeforeUnmount']
  51. const onBeforeUpdate: typeof import('vue')['onBeforeUpdate']
  52. const onClickOutside: typeof import('@vueuse/core')['onClickOutside']
  53. const onDeactivated: typeof import('vue')['onDeactivated']
  54. const onErrorCaptured: typeof import('vue')['onErrorCaptured']
  55. const onKeyStroke: typeof import('@vueuse/core')['onKeyStroke']
  56. const onLongPress: typeof import('@vueuse/core')['onLongPress']
  57. const onMounted: typeof import('vue')['onMounted']
  58. const onRenderTracked: typeof import('vue')['onRenderTracked']
  59. const onRenderTriggered: typeof import('vue')['onRenderTriggered']
  60. const onScopeDispose: typeof import('vue')['onScopeDispose']
  61. const onServerPrefetch: typeof import('vue')['onServerPrefetch']
  62. const onStartTyping: typeof import('@vueuse/core')['onStartTyping']
  63. const onUnmounted: typeof import('vue')['onUnmounted']
  64. const onUpdated: typeof import('vue')['onUpdated']
  65. const pausableWatch: typeof import('@vueuse/core')['pausableWatch']
  66. const provide: typeof import('vue')['provide']
  67. const reactify: typeof import('@vueuse/core')['reactify']
  68. const reactifyObject: typeof import('@vueuse/core')['reactifyObject']
  69. const reactive: typeof import('vue')['reactive']
  70. const reactiveComputed: typeof import('@vueuse/core')['reactiveComputed']
  71. const reactiveOmit: typeof import('@vueuse/core')['reactiveOmit']
  72. const reactivePick: typeof import('@vueuse/core')['reactivePick']
  73. const readonly: typeof import('vue')['readonly']
  74. const ref: typeof import('vue')['ref']
  75. const refAutoReset: typeof import('@vueuse/core')['refAutoReset']
  76. const refDebounced: typeof import('@vueuse/core')['refDebounced']
  77. const refDefault: typeof import('@vueuse/core')['refDefault']
  78. const refThrottled: typeof import('@vueuse/core')['refThrottled']
  79. const refWithControl: typeof import('@vueuse/core')['refWithControl']
  80. const resolveComponent: typeof import('vue')['resolveComponent']
  81. const resolveRef: typeof import('@vueuse/core')['resolveRef']
  82. const resolveUnref: typeof import('@vueuse/core')['resolveUnref']
  83. const shallowReactive: typeof import('vue')['shallowReactive']
  84. const shallowReadonly: typeof import('vue')['shallowReadonly']
  85. const shallowRef: typeof import('vue')['shallowRef']
  86. const syncRef: typeof import('@vueuse/core')['syncRef']
  87. const syncRefs: typeof import('@vueuse/core')['syncRefs']
  88. const templateRef: typeof import('@vueuse/core')['templateRef']
  89. const throttledRef: typeof import('@vueuse/core')['throttledRef']
  90. const throttledWatch: typeof import('@vueuse/core')['throttledWatch']
  91. const toRaw: typeof import('vue')['toRaw']
  92. const toReactive: typeof import('@vueuse/core')['toReactive']
  93. const toRef: typeof import('vue')['toRef']
  94. const toRefs: typeof import('vue')['toRefs']
  95. const toValue: typeof import('vue')['toValue']
  96. const triggerRef: typeof import('vue')['triggerRef']
  97. const tryOnBeforeMount: typeof import('@vueuse/core')['tryOnBeforeMount']
  98. const tryOnBeforeUnmount: typeof import('@vueuse/core')['tryOnBeforeUnmount']
  99. const tryOnMounted: typeof import('@vueuse/core')['tryOnMounted']
  100. const tryOnScopeDispose: typeof import('@vueuse/core')['tryOnScopeDispose']
  101. const tryOnUnmounted: typeof import('@vueuse/core')['tryOnUnmounted']
  102. const unref: typeof import('vue')['unref']
  103. const unrefElement: typeof import('@vueuse/core')['unrefElement']
  104. const until: typeof import('@vueuse/core')['until']
  105. const useActiveElement: typeof import('@vueuse/core')['useActiveElement']
  106. const useArrayEvery: typeof import('@vueuse/core')['useArrayEvery']
  107. const useArrayFilter: typeof import('@vueuse/core')['useArrayFilter']
  108. const useArrayFind: typeof import('@vueuse/core')['useArrayFind']
  109. const useArrayFindIndex: typeof import('@vueuse/core')['useArrayFindIndex']
  110. const useArrayFindLast: typeof import('@vueuse/core')['useArrayFindLast']
  111. const useArrayJoin: typeof import('@vueuse/core')['useArrayJoin']
  112. const useArrayMap: typeof import('@vueuse/core')['useArrayMap']
  113. const useArrayReduce: typeof import('@vueuse/core')['useArrayReduce']
  114. const useArraySome: typeof import('@vueuse/core')['useArraySome']
  115. const useArrayUnique: typeof import('@vueuse/core')['useArrayUnique']
  116. const useAsyncQueue: typeof import('@vueuse/core')['useAsyncQueue']
  117. const useAsyncState: typeof import('@vueuse/core')['useAsyncState']
  118. const useAttrs: typeof import('vue')['useAttrs']
  119. const useBase64: typeof import('@vueuse/core')['useBase64']
  120. const useBattery: typeof import('@vueuse/core')['useBattery']
  121. const useBluetooth: typeof import('@vueuse/core')['useBluetooth']
  122. const useBreakpoints: typeof import('@vueuse/core')['useBreakpoints']
  123. const useBroadcastChannel: typeof import('@vueuse/core')['useBroadcastChannel']
  124. const useBrowserLocation: typeof import('@vueuse/core')['useBrowserLocation']
  125. const useCached: typeof import('@vueuse/core')['useCached']
  126. const useClipboard: typeof import('@vueuse/core')['useClipboard']
  127. const useCloned: typeof import('@vueuse/core')['useCloned']
  128. const useColorMode: typeof import('@vueuse/core')['useColorMode']
  129. const useConfirmDialog: typeof import('@vueuse/core')['useConfirmDialog']
  130. const useCounter: typeof import('@vueuse/core')['useCounter']
  131. const useCssModule: typeof import('vue')['useCssModule']
  132. const useCssVar: typeof import('@vueuse/core')['useCssVar']
  133. const useCssVars: typeof import('vue')['useCssVars']
  134. const useCurrentElement: typeof import('@vueuse/core')['useCurrentElement']
  135. const useCycleList: typeof import('@vueuse/core')['useCycleList']
  136. const useDark: typeof import('@vueuse/core')['useDark']
  137. const useDateFormat: typeof import('@vueuse/core')['useDateFormat']
  138. const useDebounce: typeof import('@vueuse/core')['useDebounce']
  139. const useDebounceFn: typeof import('@vueuse/core')['useDebounceFn']
  140. const useDebouncedRefHistory: typeof import('@vueuse/core')['useDebouncedRefHistory']
  141. const useDeviceMotion: typeof import('@vueuse/core')['useDeviceMotion']
  142. const useDeviceOrientation: typeof import('@vueuse/core')['useDeviceOrientation']
  143. const useDevicePixelRatio: typeof import('@vueuse/core')['useDevicePixelRatio']
  144. const useDevicesList: typeof import('@vueuse/core')['useDevicesList']
  145. const useDisplayMedia: typeof import('@vueuse/core')['useDisplayMedia']
  146. const useDocumentVisibility: typeof import('@vueuse/core')['useDocumentVisibility']
  147. const useDraggable: typeof import('@vueuse/core')['useDraggable']
  148. const useDropZone: typeof import('@vueuse/core')['useDropZone']
  149. const useElementBounding: typeof import('@vueuse/core')['useElementBounding']
  150. const useElementByPoint: typeof import('@vueuse/core')['useElementByPoint']
  151. const useElementHover: typeof import('@vueuse/core')['useElementHover']
  152. const useElementSize: typeof import('@vueuse/core')['useElementSize']
  153. const useElementVisibility: typeof import('@vueuse/core')['useElementVisibility']
  154. const useEventBus: typeof import('@vueuse/core')['useEventBus']
  155. const useEventListener: typeof import('@vueuse/core')['useEventListener']
  156. const useEventSource: typeof import('@vueuse/core')['useEventSource']
  157. const useEyeDropper: typeof import('@vueuse/core')['useEyeDropper']
  158. const useFavicon: typeof import('@vueuse/core')['useFavicon']
  159. const useFetch: typeof import('@vueuse/core')['useFetch']
  160. const useFileDialog: typeof import('@vueuse/core')['useFileDialog']
  161. const useFileSystemAccess: typeof import('@vueuse/core')['useFileSystemAccess']
  162. const useFocus: typeof import('@vueuse/core')['useFocus']
  163. const useFocusWithin: typeof import('@vueuse/core')['useFocusWithin']
  164. const useFps: typeof import('@vueuse/core')['useFps']
  165. const useFullscreen: typeof import('@vueuse/core')['useFullscreen']
  166. const useGamepad: typeof import('@vueuse/core')['useGamepad']
  167. const useGeolocation: typeof import('@vueuse/core')['useGeolocation']
  168. const useIdle: typeof import('@vueuse/core')['useIdle']
  169. const useImage: typeof import('@vueuse/core')['useImage']
  170. const useInfiniteScroll: typeof import('@vueuse/core')['useInfiniteScroll']
  171. const useIntersectionObserver: typeof import('@vueuse/core')['useIntersectionObserver']
  172. const useInterval: typeof import('@vueuse/core')['useInterval']
  173. const useIntervalFn: typeof import('@vueuse/core')['useIntervalFn']
  174. const useKeyModifier: typeof import('@vueuse/core')['useKeyModifier']
  175. const useLastChanged: typeof import('@vueuse/core')['useLastChanged']
  176. const useLink: typeof import('vue-router')['useLink']
  177. const useLocalStorage: typeof import('@vueuse/core')['useLocalStorage']
  178. const useMagicKeys: typeof import('@vueuse/core')['useMagicKeys']
  179. const useManualRefHistory: typeof import('@vueuse/core')['useManualRefHistory']
  180. const useMediaControls: typeof import('@vueuse/core')['useMediaControls']
  181. const useMediaQuery: typeof import('@vueuse/core')['useMediaQuery']
  182. const useMemoize: typeof import('@vueuse/core')['useMemoize']
  183. const useMemory: typeof import('@vueuse/core')['useMemory']
  184. const useMounted: typeof import('@vueuse/core')['useMounted']
  185. const useMouse: typeof import('@vueuse/core')['useMouse']
  186. const useMouseInElement: typeof import('@vueuse/core')['useMouseInElement']
  187. const useMousePressed: typeof import('@vueuse/core')['useMousePressed']
  188. const useMutationObserver: typeof import('@vueuse/core')['useMutationObserver']
  189. const useNavigatorLanguage: typeof import('@vueuse/core')['useNavigatorLanguage']
  190. const useNetwork: typeof import('@vueuse/core')['useNetwork']
  191. const useNow: typeof import('@vueuse/core')['useNow']
  192. const useObjectUrl: typeof import('@vueuse/core')['useObjectUrl']
  193. const useOffsetPagination: typeof import('@vueuse/core')['useOffsetPagination']
  194. const useOnline: typeof import('@vueuse/core')['useOnline']
  195. const usePageLeave: typeof import('@vueuse/core')['usePageLeave']
  196. const useParallax: typeof import('@vueuse/core')['useParallax']
  197. const usePermission: typeof import('@vueuse/core')['usePermission']
  198. const usePointer: typeof import('@vueuse/core')['usePointer']
  199. const usePointerLock: typeof import('@vueuse/core')['usePointerLock']
  200. const usePointerSwipe: typeof import('@vueuse/core')['usePointerSwipe']
  201. const usePreferredColorScheme: typeof import('@vueuse/core')['usePreferredColorScheme']
  202. const usePreferredContrast: typeof import('@vueuse/core')['usePreferredContrast']
  203. const usePreferredDark: typeof import('@vueuse/core')['usePreferredDark']
  204. const usePreferredLanguages: typeof import('@vueuse/core')['usePreferredLanguages']
  205. const usePreferredReducedMotion: typeof import('@vueuse/core')['usePreferredReducedMotion']
  206. const usePrevious: typeof import('@vueuse/core')['usePrevious']
  207. const useRafFn: typeof import('@vueuse/core')['useRafFn']
  208. const useRefHistory: typeof import('@vueuse/core')['useRefHistory']
  209. const useResizeObserver: typeof import('@vueuse/core')['useResizeObserver']
  210. const useRoute: typeof import('vue-router')['useRoute']
  211. const useRouter: typeof import('vue-router')['useRouter']
  212. const useScreenOrientation: typeof import('@vueuse/core')['useScreenOrientation']
  213. const useScreenSafeArea: typeof import('@vueuse/core')['useScreenSafeArea']
  214. const useScriptTag: typeof import('@vueuse/core')['useScriptTag']
  215. const useScroll: typeof import('@vueuse/core')['useScroll']
  216. const useScrollLock: typeof import('@vueuse/core')['useScrollLock']
  217. const useSessionStorage: typeof import('@vueuse/core')['useSessionStorage']
  218. const useShare: typeof import('@vueuse/core')['useShare']
  219. const useSlots: typeof import('vue')['useSlots']
  220. const useSorted: typeof import('@vueuse/core')['useSorted']
  221. const useSpeechRecognition: typeof import('@vueuse/core')['useSpeechRecognition']
  222. const useSpeechSynthesis: typeof import('@vueuse/core')['useSpeechSynthesis']
  223. const useStepper: typeof import('@vueuse/core')['useStepper']
  224. const useStorage: typeof import('@vueuse/core')['useStorage']
  225. const useStorageAsync: typeof import('@vueuse/core')['useStorageAsync']
  226. const useStyleTag: typeof import('@vueuse/core')['useStyleTag']
  227. const useSupported: typeof import('@vueuse/core')['useSupported']
  228. const useSwipe: typeof import('@vueuse/core')['useSwipe']
  229. const useTemplateRefsList: typeof import('@vueuse/core')['useTemplateRefsList']
  230. const useTextDirection: typeof import('@vueuse/core')['useTextDirection']
  231. const useTextSelection: typeof import('@vueuse/core')['useTextSelection']
  232. const useTextareaAutosize: typeof import('@vueuse/core')['useTextareaAutosize']
  233. const useThrottle: typeof import('@vueuse/core')['useThrottle']
  234. const useThrottleFn: typeof import('@vueuse/core')['useThrottleFn']
  235. const useThrottledRefHistory: typeof import('@vueuse/core')['useThrottledRefHistory']
  236. const useTimeAgo: typeof import('@vueuse/core')['useTimeAgo']
  237. const useTimeout: typeof import('@vueuse/core')['useTimeout']
  238. const useTimeoutFn: typeof import('@vueuse/core')['useTimeoutFn']
  239. const useTimeoutPoll: typeof import('@vueuse/core')['useTimeoutPoll']
  240. const useTimestamp: typeof import('@vueuse/core')['useTimestamp']
  241. const useTitle: typeof import('@vueuse/core')['useTitle']
  242. const useToNumber: typeof import('@vueuse/core')['useToNumber']
  243. const useToString: typeof import('@vueuse/core')['useToString']
  244. const useToggle: typeof import('@vueuse/core')['useToggle']
  245. const useTransition: typeof import('@vueuse/core')['useTransition']
  246. const useUrlSearchParams: typeof import('@vueuse/core')['useUrlSearchParams']
  247. const useUserMedia: typeof import('@vueuse/core')['useUserMedia']
  248. const useVModel: typeof import('@vueuse/core')['useVModel']
  249. const useVModels: typeof import('@vueuse/core')['useVModels']
  250. const useVibrate: typeof import('@vueuse/core')['useVibrate']
  251. const useVirtualList: typeof import('@vueuse/core')['useVirtualList']
  252. const useWakeLock: typeof import('@vueuse/core')['useWakeLock']
  253. const useWebNotification: typeof import('@vueuse/core')['useWebNotification']
  254. const useWebSocket: typeof import('@vueuse/core')['useWebSocket']
  255. const useWebWorker: typeof import('@vueuse/core')['useWebWorker']
  256. const useWebWorkerFn: typeof import('@vueuse/core')['useWebWorkerFn']
  257. const useWindowFocus: typeof import('@vueuse/core')['useWindowFocus']
  258. const useWindowScroll: typeof import('@vueuse/core')['useWindowScroll']
  259. const useWindowSize: typeof import('@vueuse/core')['useWindowSize']
  260. const watch: typeof import('vue')['watch']
  261. const watchArray: typeof import('@vueuse/core')['watchArray']
  262. const watchAtMost: typeof import('@vueuse/core')['watchAtMost']
  263. const watchDebounced: typeof import('@vueuse/core')['watchDebounced']
  264. const watchEffect: typeof import('vue')['watchEffect']
  265. const watchIgnorable: typeof import('@vueuse/core')['watchIgnorable']
  266. const watchOnce: typeof import('@vueuse/core')['watchOnce']
  267. const watchPausable: typeof import('@vueuse/core')['watchPausable']
  268. const watchPostEffect: typeof import('vue')['watchPostEffect']
  269. const watchSyncEffect: typeof import('vue')['watchSyncEffect']
  270. const watchThrottled: typeof import('@vueuse/core')['watchThrottled']
  271. const watchTriggerable: typeof import('@vueuse/core')['watchTriggerable']
  272. const watchWithFilter: typeof import('@vueuse/core')['watchWithFilter']
  273. const whenever: typeof import('@vueuse/core')['whenever']
  274. }
  275. // for type re-export
  276. declare global {
  277. // @ts-ignore
  278. export type { Component, ComponentPublicInstance, ComputedRef, InjectionKey, PropType, Ref, VNode } from 'vue'
  279. }

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/菜鸟追梦旅行/article/detail/86243
推荐阅读
相关标签
  

闽ICP备14008679号