天天看點

圖檔img标簽 src拼接路徑問題

剛接觸vue,v-for中擷取字段都很正常,但是

圖檔img标簽 src拼接路徑問題

中的路徑不知道怎麼拼接。還是我張哥出馬,一個趕倆。廢話少說直接上代碼。

在vm執行個體中的data加上url:window.fileUrl,擷取路徑,然後在拼接。

vue

<div class="people_up block_hover" v-for="(item,index) in peopleArr" :key='item.rowId' @click="Lclick(item.rowGuid)">
                                <div class="picture"><img :src="url+item.peoplePic"></div>
                                <div class="name" id="f_people">{{item.name}}</div>
                                <div class="position" >{{item.address}}</div>
                            </div>

<script>

var vm = new Vue({
                el: '#peoples',
                data: {                
                    peopleArr:[],
                    url:window.fileUrl    //擷取圖檔的路徑字首
                },
                mounted:function(){
                    this.initInfo('1')
                },
                methods:{
                     initInfo:function(){
                      let self = this;
                      $.ajax({
                           async: true,
                           url: window.serverUrl+'/lxtz/lxtzpeople/getPeople',
                           method: 'get',
                           dataType: 'JSON',
                            /* data:{
                               "categoryCode":''
                           }, */
                           success: function (res) {
                              self.peopleArr = res.data
                              console.log(res.data)                             
                           },
                           error: function (data) {
                               if (data.status == 0) {
                                   parent.layer.close(parent.layer.index);
                               }
                           }
                       });
                     },
                     Lclick(msg){
                         window.open('people.html?rowGuid='+msg);
                         console.log(msg);
                     }

                },
                })
           

繼續閱讀