How to read the path of a picture in a local Json file in vue

how to read the path of a picture in a local Json file in vue

{

"about":[
    {"url":"require("./assets/img/about1.jpg")"},
    {"url":"../../assets/img/about2.jpg"},
    {"url":"../img/about3.jpg"}
],

}

clipboard.png

clipboard.png

referenced in the component Addressz

< el-col: xs= "24": sm= "8": lg= "8": xl= "8" class= "mt10 mtbox" v for = "ab in about": key= "ab.url" >

      <div class="max-box">
        <div class="tc"><img :src="ab.url"></div>
        

{{ab.p1}}

{{ab.p2}}

</div>

< / el-col >

import data from". / assets/json/data.json"
export default {
name: "Address",
data () {

return{
  about:[]
}

},
mounted () {

this.about = data.about;

}
}

the problem is that the text is displayed, the picture is not displayed, and it cannot be displayed with the above three path degrees. What is the problem

?
Mar.10,2021

I can't read it.

what is stored in your json is the assets address at the time of development, and the part of your logical image rendering path belongs to the business code running on the browser, so assets does not exist for your business code. This is the code for two sets of environments.

you can use import to introduce the image and store it in the about object (the object is not a json file), or put it in static, using an absolute path.

In the

vue-cli directory, only static files placed in the static directory can be accessed externally. If you want to introduce a picture address in JSON (static/mock/index.json), you must put the picture in the static directory. Then the address of the picture in JSON is the address where your vue component introduces the image. I introduced static/img/1.jpg pictures into src/component/home/home.vue at the address of ".. / static/img/1.jpg". The address in JSON should also be written in the same way. If you are not sure about the image address when configuring JSON, you can directly introduce a picture into your corresponding VUE component to test the address, and then put it in JSON.


have you solved it, bosses

MySQL Query : SELECT * FROM `codeshelper`.`v9_news` WHERE status=99 AND catid='6' ORDER BY rand() LIMIT 5
MySQL Error : Disk full (/tmp/#sql-temptable-64f5-1b35e3d-2b748.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
MySQL Errno : 1021
Message : Disk full (/tmp/#sql-temptable-64f5-1b35e3d-2b748.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
Need Help?