[DONE] A non-comment is a loaded
I just start using vue.js with "vue-cli" just now.
but, now I faced a problem.
purpose : I want the parent component to pass the image path to the child component as a string, and the child to load the image using it.
However, in the process of bundling the webpack, It can not call it unless it have to do hash processing like other images, only first image components work. Do I need to configure vue.config.js differently? Or is it possible to change the way an image is called in a vue?
thanks.
<template lang="pug">
.container
img(src="../assets/image/logo.png")
//- img(style='{ "width" : "200px" , "height" : "200px" }' :style="{backgroundImage : logoSrcUrl }")
//- img(:src="logoSrc")
//- img(:src="logoSrcUrl")
//- img(:src="logoSrcRequire")
img(:src="getImg(this.$props.imgSrc)")
img(:src="stringRequire")
//- img(:src="logoSrcData")
//- img(:src="logoSrcDataUrl")
</template>
<script>
export default {
props : {
"imageDir" : String,
"imgSrc" : String,
},
data(){
return {
logoSrcData : '',
}
},
computed : {
logoSrc(){
return this.$props.imageDir + this.$props.imgSrc
},
logoSrcRequire(){
return require(this.logoSrcData)
},
stringRequire(){
return require("../assets/image/logo.png")
},
logoSrcUrl(){
return `url(${this.$props.imageDir}${this.$props.imgSrc})`
},
logoSrcDataUrl(){
return `url(${this.logoSrcData})`
},
},
methods : {
getImg(fileName){
return require('../assets/image/' + fileName)
}
},
created() {
console.log(this.$props.imageDir) // ../assets/image/
console.log(this.$props.imgSrc) // logo.png
this.$data.logoSrcData = this.$props.imageDir + this.$props.imgSrc
console.log(this.logoSrcData) // ../assets/image/logo.png
},
}
</script>
<style scoped>
</style>
In addition, when bundling with WebPack, can I implement additional work to change the hash value only for the changed image? Or does WebPack need a pre-bundler because it does not refer to previous bundling files?