1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 | </template> <q-carousel class="bans" animated v-model="slide" arrows navigation infinite :autoplay="2500" v-if="item.storeInfo" > // v-if="item.storeInfo" 此处是因为之前sliderImageArr报错undefined <q-carousel-slide :name="index" v-for="(it, index) in item.storeInfo.sliderImageArr" :key="index" :img-src="`http://192.168.60.174:8001/file${it.split('/file')[1]}`" /> // :name="index" 名称 // v-for="(it, index) in item.storeInfo.sliderImageArr" 得到sliderImageArr数组图片 // img-src="`http://192.xxx.xx.174:8001/file${it.split('/file')[1]}`" 对图片路径进行拼接和截取 // split('/file')[1] 的[1]是因为split截取到的是数组 </q-carousel> </template> <script> export default { data() { return { slide: 1, // 此处的1 等于 :name="index" item: {}, sliderImageArr: [] } }, created() { this.getList(); }, methods: { getList() { let id = this.$route.query.id; this.$axios({ method: "get", url: "http://192.xx.xx.174:8000/api/product/detail/" + id, headers: { Authorization: window.sessionStorage.getItem("token") } }) .then(res => { this.item = res.data.data this.sliderImageArr = res.data.data.storeInfo.sliderImageArr console.log(res.data.data.storeInfo.sliderImageArr) }) .catch(function(error) { console.log(error); }) }, </script> |
- 数据样式为
1.png
PS.可以看到sliderImageArr里面的图片路径为http://127.0.0.1:8001/file/pic/20201202131124990710.png或是http://127.0.0.1:8001/api/file/pic/20201202131124990710.png,但是这里要替换为http://192.xxx.xx.174:8001/file/pic/20201202131124990710.png,所以从/file处截取