我在使用mint-ui中,搭配使用vue的v-if指令,但是发现没有效果,代码如下
<mt-cell :title="item.courseName" class="left" v-for="(item,index) in courseList" is-link :to="{ name: 's_myPaperList', params: { lessonId: item.lessonId ,teacherId:item.teacherId}} ">
<mt-badge type="primary" v-if="item.paperToCheckCount > 0">{{item.paperToCheckCount}}</mt-badge>
</mt-cell>
v-if这一行无效,item.paperToCheckCount确实是大于零,可以无效。
我怀疑是我获取数据的方式有问题
我是通过axios获取数据的
this.$http.post('/getStudentLList', {
studentId: window._const.studentId,
}).then((res) => {
for (let key in res.data.lessonList) {
if (res.data.lessonList.hasOwnProperty(key)) {
this.courseList.push({
courseName: res.data.lessonList[key].courseName,
lessonId: res.data.lessonList[key]._id,
teacherId: res.data.lessonList[key].teacherId,
})
this.$http.post('/getPaperToCheckCount', {
lessonId: res.data.lessonList[key]._id,
studentId: window._const.studentId,
}).then((res_in) => {
this.courseList[key].paperToCheckCount = res_in.data.paperToCheckCount
})
}
}
})
我是先获取lessonId,再通过lessonId获取paperToCheckCount
item.paperToCheckCount这个值确定是数值型的么 v-if="~~item.paperToCheckCount > 0" 呢?