【发布时间】:2017-08-30 16:43:06
【问题描述】:
我正在尝试根据数据触发一个隐藏或显示图像的函数,我编写了两个函数,一个调用创建的钩子中的 api,第二个函数渲染图像。问题是我如何在加载 dom 后调用第二个函数,现在当我尝试调用第一个函数或创建它时返回我的错误,即 css 无法更改为 null。我尝试使用挂载函数newtick 但它仍然首先触发 render_badges 函数,因此内部值为 null
创建:函数(){ this.loadlike()
},
methods:{
loadlike:function(){
var self = this
this.$http.get('/api/user_profile').then(function (res) {
self.tasksdata = res.body
self.badges = self.tasksdata.data2
console.log(self.badges)
console.log(this.tasksdata)
console.log(this.max)
})
},
getHumanDate : function (date) {
return moment(date, 'YYYY-MM-DD hh-mm-ss').locale("en-gb").format('LL');
},
render_badges:function(){
var self = this
var counter = 0;
self.badges.map(function(e){
counter ++;
console.log(counter)
if(counter <=self.max){
document.getElementById("i").style.display = "initial";
}
else{
document.getElementById("i").style.display = "none";
}
})
},
mounted: function () {
this.$nextTick(function () {
this.render_badges();
})
}
【问题讨论】: