gpt4 book ai didi

typescript - vue3 vite 别名无法按预期使用 typescript

转载 作者:行者123 更新时间:2023-12-05 09:30:30 28 4
gpt4 key购买 nike

我尝试了下面线程中的所有答案,但没有成功:

`Vue3 - Vite` project alias src to @ not working

// https://vitejs.dev/config/
export default defineConfig({
resolve: {
extensions: ['.ts', '.js', '.vue'],
alias: [{
find: '@',
replacement: resolve(__dirname, 'src')
}],
},
plugins: [
vue(),
Components({
resolvers: [ElementPlusResolver()],
}),
]
})

最佳答案

在这个问题上苦苦挣扎了几个小时,在发布问题后几分钟就解决了...

还需要ts配置:

  1. 如果path 不起作用,请同时添加baseUrl 配置。
  2. 修改配置后,
  3. 重新启动 IDE。 (IntelliJ经测试不重启是不行的)

tsconfig.json

{
"compilerOptions": {
"noImplicitAny": false,
"target": "esnext",
"useDefineForClassFields": true,
"module": "esnext",
"moduleResolution": "node",
"strict": true,
"jsx": "preserve",
"sourceMap": true,
"resolveJsonModule": true,
"esModuleInterop": true,
"baseUrl": "./",
"paths": {
"@/*": [
"./src/*"
],
},
"lib": [
"esnext",
"dom"
]
},
"include": ["src/**/*.ts", "src/**/*.d.ts", "src/**/*.tsx", "src/**/*.vue"]
}

关于typescript - vue3 vite 别名无法按预期使用 typescript ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/69527016/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com