【发布时间】:2017-08-04 10:10:52
【问题描述】:
我有下一个 vue 实例:
var immobles_destacats = ($('#immobles_destacats').length > 0) ? new Vue({
el: '#immobles_destacats',
data: {
immobles: {}
},
methods: {
add: function(i) {
if (this.immobles[i].imatges.lenght == this.immobles[i].counter) {
return this.immobles[i].counter = 0;
}
return this.immobles[i].counter++;
},
substract: function(i) {
if (this.immobles[i].counter == 0) {
return this.immobles[i].counter = this.immobles[i].imatges.lenght;
}
return this.immobles[i].counter--;
}
},
mounted: function() {
$.post('get_immobles_destacats', function(immobles, textStatus, xhr) {
for (var i = 0; i < immobles.length; i++) {
immobles_destacats.immobles[i] = immobles[i];
immobles_destacats.immobles[i].counter = 0;
}
});
}
}) : null;
下一个渲染数据的 html 'immobles':
<div id="immobles_destacats">
<div v-for="(immoble, key) in immobles" class="immoble"><img v-bind:src="immoble.imatges[immoble.counter].url"/>
<input type="button" v-on:click="add(key)" value="+"/>
<input type="button" v-on:click="substract(key)" value="-"/>
</div>
</div>
如您所见,我在 mount 函数中设置了数据“immobles”,我得到了这个: 问题出现在页面加载时没有呈现任何内容,是因为数据'immobles'在填充发布请求时没有触发“onchange-renderhtml”吗?如果是这样,我怎样才能将这个“onchange-renderhtml”设置为数据“immobles”?
【问题讨论】:
-
你试过
Vue.set吗?
标签: javascript jquery html vue.js vuejs2