vue.js - Show images files using Vue.js
问题描述
I am new in Vue, i am doing examples using Vue 2.0, i am have this structure
-src
- assets
--> logo.png
- components
--> beging.vue
i am doing changes in beging.vue and i have this line
<template>
<div class="container">
<h1>Página de Inicio</h1>
<hr>
<img :src="require('../assets/logo.png')">
</div>
</template>
The problem is that in the moment i making the compilation and i publish this in my local server the image always is hidden but before to compilate i can see the image fine.
Is important mentionate that in my local server i have this structure
- assets
- dist
.htaccess
- index.html
in theory all information exist inside to dist and yes is correct in dist exist:
- build.js
- build.js.map
- logo.png
But the imagen never appear. Could you help me to understand what is the problem?
Thank u.
//UPDATE
Exist a important point, as i am using apache is neccesary make a .htaccess file in my case i am working using subfolders, according the vue documentation if the file will be in subfolder thge configuration must be:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /test/
RewriteRule ^index\.html$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.html [L]
</IfModule>
In my case the subfolder that i have is "test" when i review the code usign the inspector code from browser i can see this:
<img src="./src/assets/logo.png?82b9c7a5a3f405032b1db71a25f67021">
But if i change this manually and put this:
<img src=".test/src/assets/logo.png?82b9c7a5a3f405032b1db71a25f67021">
the image appear, but which is the configuration for put in htaccess file?
解决方案
使用@
符号指向根文件夹
<template>
<div class="container">
<h1>Página de Inicio</h1>
<hr>
<img :src="require('@/assets/logo.png')">
</div>
</template>
推荐阅读
- android - 这是关于来自outlook-email 的Android Applinks / Deeplinks 问题
- python - 由于 requirements.txt 中的问题,Heroku 中的部署失败
- javascript - 如何避免 Promise 中的重复捕获功能
- c# - C# - 尝试从函数构造一个类,得到无法转换方法组错误
- python - discord.py 如何设置一个只有管理员才能使用的 kick 命令?
- php - 上传到团队云端硬盘的权限问题
- php - 使用PHP按ID将数组拆分为相等的部分
- mysql - 撤销对 MySQL 中众多数据库之一的访问权限
- database - 根据数组中的 AND 条件过滤 ElasticSearch 结果
- java - 在java中使用递归查找数字的以2为底的对数