I am new to vue.js and trying to display a list of images using the directive v-for. Instead, I get the server responded with a status of 404 (Not Found). I am using the template generated by vue-cli .
The webpack loader url should change the url of the image corresponding item.srcto some format [name].[ext]?[hash], but it will just leave them alone (in fact, the url of the result http://localhost:8080/assets/computer.jpg).
And here is my code:
<template>
<h2 class="ui header">
<div class="content">
Recent Research
<div class="sub header">
recent research issue
</div>
</div>
</h2>
<div v-for="item in items" class="ui three column centered grid">
<div class="column">
<img class="ui centered medium image" :src="item.src" />
<h3 class="ui header">{{item.text}}</h3>
<p class="teal meta">{{item.extra}}</p>
</div>
</div>
</template>
<script>
export
default {
data() {
return {
items: [{
src: '../assets/computer.jpg',
text: 'fundamentals of search engine',
extra: 'with Google'
}, {
src: '../assets/computer.jpg',
text: 'fundamentals of search engine',
extra: 'with Google'
}, {
src: '../assets/computer.jpg',
text: 'fundamentals of search engine',
extra: 'with Google'
}, {
src: '../assets/computer.jpg',
text: 'fundamentals of search engine',
extra: 'with Google'
}, {
src: '../assets/computer.jpg',
text: 'fundamentals of search engine',
extra: 'with Google'
}, {
src: '../assets/computer.jpg',
text: 'fundamentals of search engine',
extra: 'with Google'
},
]
}
}
}
</script>
Run codeHide resultAnd the related webpack configuration.
var path = require('path')
module.exports = {
entry: {
app: './src/main.js'
},
output: {
path: path.resolve(__dirname, '../dist/static'),
publicPath: '/static/',
filename: '[name].js'
},
resolve: {
extensions: ['', '.js', '.vue'],
alias: {
'src': path.resolve(__dirname, '../src')
}
},
resolveLoader: {
root: path.join(__dirname, 'node_modules'),
},
module: {
loaders: [{
test: /\.vue$/,
loader: 'vue'
}, {
test: /\.js$/,
loader: 'babel',
exclude: /node_modules/
}, {
test: /\.json$/,
loader: 'json'
}, {
test: /\.(png|jpg|gif|svg)$/,
loader: 'url',
query: {
limit: 10000,
name: '[name].[ext]?[hash]'
}
}]
},
vue: {
loaders: {
js: 'babel'
}
}
}
Run codeHide result
温 发 琥 source
share