[英]Vue 3, Vuetify 3, Vue-CLI, and TypeScript static asset path
I'm leveraging one of the Vuetify 3.0.4 Beta template, I notice that when I include an image in the assets folder- if I perform a build I do not see the included image in my bundle.我正在利用 Vuetify 3.0.4 Beta 模板之一,我注意到当我在资产文件夹中包含图像时 - 如果我执行构建,我不会在我的包中看到包含的图像。 The current structure:目前的结构:
root
- dist
- public
- src
- - assets
- - - logo.png
- - views
- - components
- - App.vue
- - main.ts
So, if I access a relative path inside a view via:因此,如果我通过以下方式访问视图内的相对路径:
<v-img src="../assets/logo.png" />
The asset will be included in my bundle, but if I attempt to access via the App.vue
I continually get a 404 asset not found.该资产将包含在我的捆绑包中,但如果我尝试通过App.vue
访问,我会不断收到 404 未找到资产。 Inside the App.vue
I have done both of these:在App.vue
里面我做了这两个:
<v-img src="@assets/logo.png" />
<v-img src="@/assets/logo.png" />
The @
should automatically point to root/src path- but for some odd reason it is not being included in the bundle. @
应该自动指向 root/src 路径,但由于某些奇怪的原因,它没有包含在包中。 Any thoughts would be terrific-任何想法都会很棒-
vue --version
@vue/cli 5.0.6
I do the following:我执行以下操作:
vue create client
Vue CLI v5.0.6
? Please pick a preset: Manually select features
? Check the features needed for your project: Babel, TS, Router, Vuex, CSS Pre-processors, Linter
? Choose a version of Vue.js that you want to start the project with 3.x
? Use class-style component syntax? Yes
? Use Babel alongside TypeScript (required for modern mode, auto-detected polyfills, transpiling JSX)? Yes
? Use history mode for router? (Requires proper server setup for index fallback in production) Yes
? Pick a CSS pre-processor (PostCSS, Autoprefixer and CSS Modules are supported by default): Sass/SCSS (with dart-sass)
? Pick a linter / formatter config: Prettier
? Pick additional lint features: Lint on save, Lint and fix on commit
? Where do you prefer placing config for Babel, ESLint, etc.? In dedicated config files
? Save this as a preset for future projects? No
cd "client"
vue add vuetify
? Choose a preset: Vuetify 3 Preview (Vuetify 3)
? Would you like to install Vuetify 3 nightly build? (WARNING: Nightly builds are intended for development testing and may include bugs or other issues.) No
Then I add an image directly into the assets folder, then in the "app.vue" I immediately go add my the <v-img src=".." />
to the path of the new image and I do not see the assets folder being included in the console window and continue to get a 404 resource not found.然后我直接将图像添加到资产文件夹中,然后在“app.vue”中我立即将我的<v-img src=".." />
添加到新图像的路径中,我没有看到assets 文件夹被包含在控制台窗口中并继续获取 404 资源未找到。
GET http://localhost:8080/assets/images/application-title.png 404 (Not Found)
If I traverse the page source, I do not see it included as a resource either after I build.如果我遍历页面源,在构建之后我也不会看到它作为资源包含在内。
The problem is vue-loader
does not automatically transform <v-img>.src
into a require
call (unlike <img>.src
).问题是vue-loader
不会自动将<v-img>.src
转换为require
调用(与<img>.src
不同)。
You can manually add the require
call in your src
binding:您可以在src
绑定中手动添加require
调用:
<v-img :src="require('@/assets/application-title.png')" />
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.