You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Check that there isn't already an issue that reports the same bug to avoid creating a duplicate.
Make sure this is a Vite issue and not a framework-specific issue. For example, if it's a Vue SFC related bug, it should likely be reported to vuejs/core instead.
Describe the bug
vite.config.ts 配置如下:
`import { fileURLToPath, URL } from 'node:url';
import { defineConfig } from 'vite';
import vue from '@vitejs/plugin-vue';
const getFileURLToPath = (url: string): string => {
return fileURLToPath(new URL(url, import.meta.url));
};
export default defineConfig({
publicDir: getFileURLToPath('./public'), // 公共静态资源
root: getFileURLToPath('./src/Project/bc_a_1'),
base: '/h5_release_1/bc_a_1',
envDir: getFileURLToPath('./'), // 用于加载 .env 文件的目录。可以是一个绝对路径,也可以是相对于项目根的路径。
plugins: [
vue(),
],
resolve: {
alias: {
'@': getFileURLToPath('./src')
}
},
server: {
host: true,
port: 8082,
}
});`
项目目录结构如下
在App.vue 引入 import HelloWorld from '@/components/HelloWorld.vue'
然后在子组件HelloWorld.vue 写入如下代码:
<template> <img src="/1.png" alt="" /> </template>
/1.png 在 public 目录下 这种情况下他不会正常显示
但是当我在 App.vue 顶级组件中写入
<img src="/1.png" alt="" />
就可以正常显示,显示结果如下:可以看出 src 的路径在顶级组件 和子组件中显示不一样
Vite4.5.1 是可以正常显示的
Reproduction
https://github.com/suncohey/vue3ye
Steps to reproduce
Run
yarn
followed byyarn dev
System Info
Used Package Manager
yarn
Logs
No response
Validations
The text was updated successfully, but these errors were encountered: