简体   繁体   English

Vue 3、Vuetify 3、Vue-CLI 和 TypeScript 静态资产路径

[英]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-任何想法都会很棒-


Update:更新:

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')" />

GitHub fix GitHub 修复

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 vue-cli 服务忽略目录上的打字稿类型错误 - vue-cli service ignore typescript type errors on directory Vue-CLI、TypeScript 和 monorepo:如何在 /src 之外声明类型? - Vue-CLI, TypeScript and monorepo: how to declare types outside of /src? 无法使用TypeScript在Vue-cli 2上安装组件 - Failed to mount component on Vue-cli 2 using TypeScript 尝试将 vue-cli 项目迁移到 typescript 时出错 - Error when trying to migrate vue-cli project to typescript 如何使用 typescript/vue-router/vuex/ 但不使用 vue-cli 创建 vue.js3 应用程序 - How to create vue.js3 app using typescript/vue-router/vuex/ but without vue-cli Vue Cli 3 - Typescript - Vuetify 样式不适用于带有 @WithRender 的单独模板文件 - Vue Cli 3 - Typescript - Vuetify styles not working with separate template file with @WithRender 同步VSCode linting和vue-cli linting - Synchronising VSCode linting with vue-cli linting vue-cli 构建失败并出现编译错误 - vue-cli build fails with compile errors 如何在带有 typescript 的 vue-cli 中使用自定义服务工作者事件 - How can I use a custom service worker events in vue-cli with typescript 使用 vue-cli 为 background.js 文件在打字稿中构建 chrome 扩展 - building a chrome extension in typescript with vue-cli for the background.js file
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM