html
<div class="content_img clear">
<a :href="img.src" class="block" v-bind:style="{backgroundImage: 'url(' + img.url + ')'}" v-for="(img,index) in filteredStyle">
<div class="tx">{{img.name}}</div>
<div class="xq">
<div>
<span class="fl">{{img.type}}</span>
<span class="fl n">1张</span>
</div>
</div>
<span class="sc" v-on:click="sC(img.url,img.type,index)" :class="{'a':classItem.indexOf(img.url)>=0}" v-on:click.prevent=""></span>
</a>
</div>
js
data: {
img: { url:"",name:"",type:""}, imgS:[]
}
mounted: function(){
Vue.http.get('js/common1.json').then((response) => {
console.log(1)
vm.$data.imgS=response.data;
})
},
computed: {
filteredStyle: function () {
console.log(2);
var self = this;
console(this.imgS[0]);
return this.imgS[0];
}
}
运行结果是
2//先运行computed
1//运行mounted
2//数据变化再次执行computed
imgS[0]的值//能够打印出值,但是不能提供给html里面,所以页面没有变化
问题:怎么样才能得到computed第二次执行的数据呢?是不是它只传递第一次的值呢?
直接賦值就好了,不需要經過computed