demo\vite.config.js 配置路径别名@
import { defineConfig } from 'vite'
import vue from '@vitejs/plugin-vue'
import path from 'path' //导入 node.js path
// https://vitejs.dev/config/
export default defineConfig({
plugins: [vue()],
resolve: {
alias: { //配置路径别名
'@': path.resolve(__dirname, 'src')
}
}
})
demo\jsconfig.json VSCode路径提示 [js]
{
"compilerOptions": {
"baseUrl": ".",
"paths": {
"@/*": ["src/*"] // 配置 @ 符号指向 src 目录及其子目录
}
}
}
demo\src\router\index.js
import { createRouter, createWebHashHistory, createWebHistory } from "vue-router"
const routes = [
{
path: "/", // http://localhost:5173
// component: () => import("../view/index.vue")
component: () => import("@/view/index.vue")
},
{
path: "/content", // http://localhost:5173/content
component: () => import("@/view/content.vue")
},
]
const router = createRouter({
// 使用url的#符号之后的部分模拟url路径的变化,因为不会触发页面刷新,所以不需要服务端支持
// history: createWebHashHistory(),
history: createWebHistory(),
routes
})
export default router
2.配置路径别名@和VSCode路径提示
-- 未经授权禁止转载 --