1.config.js 文件中配置
引入resolve
import { resolve } from "path";
export default defineConfig({
plugins: [
vue()
],
//添加此段
resolve: {
alias: {
"@": resolve(__dirname, "src"), // 设置@指向src
"@components": resolve(__dirname, "src/components"), // 设置@components指向src/components
},
},
});
2.在根目录下的tsconfig.json文件中添加配置
"lib": ["ESNext", "DOM"],
"skipLibCheck": true,
"noEmit": true,
//看缺啥补啥
"baseUrl": "./",
"paths": {
"@/*": [
"./src/*"
],
"@components/*": [
"./src/components/*"
],
}
},
"include": ["src/**/*.ts", "src/**/*.d.ts", "src/**/*.tsx", "src/**/*.vue"],
"references": [{ "path": "./tsconfig.node.json" }]