<template>
<div v-for="item in itemList">
<div class="item-picture" :style="{ 'backgroundImage' : 'url(' +
item.picture + ')' }"></div>
<p>{{item.name}}</p>
<p>{{item.address}}</p>
</div>
</div>
</template>
<script>
import axios from 'axios'
export default {
name: ‘name1’,
props: [
‘objects1’
],
data () {
return {
objects2: [],
}
},
watch: {
objects1: function () {
this.objects2 = this.objects1
for (let i = 0; i < this.objects2.length; i++) {
this.getPic(this.objects2[i].url, i)
}
},
},
mounted () {
},
updated () {
},
methods: {
getPic (url, index) {
let _this = this
axios.get(url)
.then((res) => {
_this.objects2[index].picture = res.data.url
}
})
.catch((error) => {
})
},
}
}
答案 0 :(得分:1)
尝试使用Vue.set
并查看文档中的更改检测警告(https://vuejs.org/v2/guide/reactivity.html#Change-Detection-Caveats)
而不是
_this.objects2[index].picture = res.data.url
使用
Vue.set(this.objects2[index], 'picture', res.data.url)