图片img标签 src拼接路径问题

野性酷女 2023-01-07 08:56 292阅读 0赞

刚接触vue,v-for中获取字段都很正常,但是![Image 1][]中的路径不知道怎么拼接。还是我张哥出马,一个赶俩。废话少说直接上代码。

在vm实例中的data加上url:window.fileUrl,获取路径,然后在拼接。

vue

  1. <div class="people_up block_hover" v-for="(item,index) in peopleArr" :key='item.rowId' @click="Lclick(item.rowGuid)">
  2. <div class="picture"><img :src="url+item.peoplePic"></div>
  3. <div class="name" id="f_people">{ { item.name}}</div>
  4. <div class="position" >{ { item.address}}</div>
  5. </div>
  6. <script>
  7. var vm = new Vue({
  8. el: '#peoples',
  9. data: {
  10. peopleArr:[],
  11. url:window.fileUrl //获取图片的路径前缀
  12. },
  13. mounted:function(){
  14. this.initInfo('1')
  15. },
  16. methods:{
  17. initInfo:function(){
  18. let self = this;
  19. $.ajax({
  20. async: true,
  21. url: window.serverUrl+'/lxtz/lxtzpeople/getPeople',
  22. method: 'get',
  23. dataType: 'JSON',
  24. /* data:{
  25. "categoryCode":''
  26. }, */
  27. success: function (res) {
  28. self.peopleArr = res.data
  29. console.log(res.data)
  30. },
  31. error: function (data) {
  32. if (data.status == 0) {
  33. parent.layer.close(parent.layer.index);
  34. }
  35. }
  36. });
  37. },
  38. Lclick(msg){
  39. window.open('people.html?rowGuid='+msg);
  40. console.log(msg);
  41. }
  42. },
  43. })

[Image 1]:

发表评论

表情:
评论列表 (有 0 条评论,292人围观)

还没有评论,来说两句吧...

相关阅读

    相关 imgsrc 中文路径解决办法

    最近有个项目场景如下:需要后台遍历图片、视频所在的文件夹,获取的到的路径传递到JSP页面,使用<img src="具体的路径">显示图片。遇到的问题:如果图片的路径、图片名存在