<;img src=”等&引用&燃气轮机;在内置vuejs/webpack后正在生成不同的路径
我是Vuejs的新手。我在一个项目中工作,我必须在Vue组件中显示图像。在我的组件中,我显示如下图像:<;img src=”等&引用&燃气轮机;在内置vuejs/webpack后正在生成不同的路径,webpack,vuejs2,Webpack,Vuejs2,我是Vuejs的新手。我在一个项目中工作,我必须在Vue组件中显示图像。在我的组件中,我显示如下图像: 然后建成后就不显示了。当我检查我的代码时,它会显示不同的地址,如下所示: 我的文件夹结构是: 资产 组成部分 VueTemplate.vue//这是我显示图像的地方 图像 back-arrow.png js//npm运行生成位置 我不知道为什么会改变,有人能帮我吗?短暂性脑缺血发作 我的网页包配置: var path = require('path') var webpac
然后建成后就不显示了。当我检查我的代码时,它会显示不同的地址,如下所示:
我的文件夹结构是:
- 资产
- 组成部分
- VueTemplate.vue//这是我显示图像的地方
- 图像
- back-arrow.png
- js//npm运行生成位置
- 组成部分
var path = require('path')
var webpack = require('webpack')
module.exports = {
entry: './admin/assets/main.js',
output: {
path: path.resolve(__dirname, 'admin/js'),
publicPath: '/js/',
filename: 'graphs-lite-admin.js'
},
module: {
rules: [
{
test: /\.css$/,
use: [
'vue-style-loader',
'css-loader'
],
},
{
test: /\.scss$/,
use: [
'vue-style-loader',
'css-loader',
'sass-loader'
],
},
{
test: /\.sass$/,
use: [
'vue-style-loader',
'css-loader',
'sass-loader?indentedSyntax'
],
},
{
test: /\.vue$/,
loader: 'vue-loader',
options: {
loaders: {
// Since sass-loader (weirdly) has SCSS as its default parse mode, we map
// the "scss" and "sass" values for the lang attribute to the right configs here.
// other preprocessors should work out of the box, no loader config like this necessary.
'scss': [
'vue-style-loader',
'css-loader',
'sass-loader'
],
'sass': [
'vue-style-loader',
'css-loader',
'sass-loader?indentedSyntax'
]
}
// other vue-loader options go here
}
},
{
test: /\.js$/,
loader: 'babel-loader',
exclude: /node_modules/
},
{
test: /\.(png|jpg|gif|svg)$/,
exclude: /node_modules/,
loader: 'file-loader',
options: {
name: '[name].[ext]',
outputPath: 'images/'
}
}
]
},
resolve: {
alias: {
'vue$': 'vue/dist/vue.esm.js'
},
extensions: ['*', '.js', '.vue', '.json']
},
devServer: {
historyApiFallback: true,
noInfo: true,
overlay: true
},
performance: {
hints: false
},
devtool: '#eval-source-map'
}
if (process.env.NODE_ENV === 'production') {
module.exports.devtool = '#source-map'
// http://vue-loader.vuejs.org/en/workflow/production.html
module.exports.plugins = (module.exports.plugins || []).concat([
new webpack.DefinePlugin({
'process.env': {
NODE_ENV: '"production"'
}
}),
// new webpack.optimize.UglifyJsPlugin({
// sourceMap: true,
// compress: {
// warnings: false
// }
// }),
new webpack.LoaderOptionsPlugin({
minimize: true
})
])
}
我找到了一个临时解决办法。问题出在网页包里。我不得不使用装载机。我使用了url加载器
{
test: /\.(png|jpg|gif|svg)$/,
loader: 'url-loader', //adding this line solved my problem
options: {
name: '[name].[ext]?[hash]'
}
}
如果使用vue cli 3.0创建项目,则可以使用filenameHashing选项将其删除 在项目根目录上创建
vue.config.js
文件,然后编写此文件
module.exports = {
filenameHashing: false
}
请参阅此链接:
或者,如果您正在使用webpack配置文件,请从输出中删除[hash]
output: {
filename: '[name].[hash].bundle.js'
}
url加载器将我的图像转换为base64,这是我不想要的。它不是在访问直接资产。