The newly created ". vue" file does not recognize automatically imported hooks generated through "unplugin auto import", such as "onMounted" #362
-
Issue Description:The newly created ". vue" file does not recognize automatically imported hooks generated through "unplugin auto import", such as "onMounted".VSCode must be restarted to recognize. Steps to Reproduce:
pnpm add -D unplugin-vue-router unplugin-auto-import vue-router
// the vite plugins
import vue from '@vitejs/plugin-vue';
import AutoImport from 'unplugin-auto-import/vite';
import VueRouter from 'unplugin-vue-router/vite';
import { VueRouterAutoImports } from 'unplugin-vue-router';
import type { PluginOption } from 'vite';
export function createPlugins(env: ImportMetaEnv): PluginOption[] {
return [
VueRouter({
routesFolder: ['src/views'],
dts: 'src/types/auto/auto-router.d.ts',
extensions: ['.page.vue', '.vue'],
}),
vue(),
AutoImport({
imports: [
VueRouterAutoImports,
{
'vue-router/auto': ['useLink'],
},
'vue',
],
dts: 'src/types/auto/auto-imports.d.ts'
}),
];
} // src/router/index.ts
import { createRouter, createWebHistory } from 'vue-router/auto';
const router = createRouter({
history: createWebHistory(),
});
export default router;
// main.ts
import { createApp } from 'vue';
import App from './App.vue';
import router from '@/router';
createApp(App)
.use(router)
.mount('#app'); /* tsconfig.json */
{
"compilerOptions": {
"target": "ES2020",
"jsx": "preserve",
"lib": ["ES2020", "DOM", "DOM.Iterable"],
"useDefineForClassFields": true,
"baseUrl": ".",
"module": "ESNext",
/* Bundler mode */
"moduleResolution": "bundler",
"paths": {
"@/*": ["src/*"]
},
"resolveJsonModule": true,
"types": ["unplugin-vue-router/client"],
"allowImportingTsExtensions": true,
/* Linting */
"strict": true,
"noFallthroughCasesInSwitch": true,
"noUnusedLocals": true,
"noUnusedParameters": true,
"noEmit": true,
"isolatedModules": true,
"skipLibCheck": true
},
"references": [{ "path": "./tsconfig.node.json" }],
"include": ["build/**/*.ts", "src/**/*.ts", "src/**/*.tsx", "src/**/*.vue", "src/**/*.d.ts"]
} |
Beta Was this translation helpful? Give feedback.
Answered by
camtheman256
Apr 16, 2024
Replies: 2 comments
-
Beta Was this translation helpful? Give feedback.
0 replies
Answer selected by
posva
-
我是魏健!已收到您的邮件。I'm Wei Jian! We have received your email.
|
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I've had issues with the official Vue extension recognising newly created files and providing type hints, so I don't think that this bug is because of this package. Try using "Vue: restart TS and Vue servers" in the command palette.