?在main.ts中引入router
import { createApp } from 'vue'
import './style.css'
import App from './App.vue'
import router from './router/index.js'
// 導(dǎo)入Unocss
import 'uno.css'
createApp(App).use(router).mount('#app')
報錯提示找不到路徑
[vite] Internal server error: Failed to resolve import "@/views/LoginView.vue" from "src\router\index.ts". Does the file exist?
Plugin: vite:import-analysis
File: D:/project/vue3-shopping/src/router/index.ts
4 | path: "/login",
5 | name: "Login",
6 | component: () => import("@/views/LoginView.vue"),
解決:
修改vite.config.ts配置
import { defineConfig } from 'vite'
import vue from '@vitejs/plugin-vue'
// 引入Unocss
import Unocss from 'unocss/vite';
import { presetUno, presetAttributify, presetIcons } from "unocss"
import path from 'path' // 需安裝此模塊
// https://vitejs.dev/config/
export default defineConfig({
plugins: [vue(),
Unocss({ // 使用Unocss
presets: [
presetUno(),
presetAttributify(),
presetIcons()],
})],
resolve: {
alias: { // 這里就是需要配置resolve里的別名
"@": path.join(__dirname, "./src"), // path記得引入
// 'vue': 'vue/dist/vue.esm-bundler.js' // 定義vue的別名,如果使用其他的插件,可能會用到別名
},
}
})
安裝 path模塊
三種方式,我用的第一種。
npm install --save-dev @types/node
cnpm install --save-dev @types/node
yarn add @types/node -D
配置完成以后運行文章來源:http://www.zghlxwxcb.cn/news/detail-737145.html
npm run dev
解決,撒花!文章來源地址http://www.zghlxwxcb.cn/news/detail-737145.html
到了這里,關(guān)于Failed to resolve import “@/views/index.vue“ from “src\router\index.ts“ vue3 路由配置@找不到文件的文章就介紹完了。如果您還想了解更多內(nèi)容,請在右上角搜索TOY模板網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關(guān)文章,希望大家以后多多支持TOY模板網(wǎng)!