vue为什么数据渲染不出来,后台有值,但是不显示在页面上

微信截图_20191218150727.png微信截图_20191218150809.png

//下面是代码

getInfo() {
        constuserInfo = JSON.parse(localStorage.getItem('user'))
        if (userInfo.role === 3) {
            //调取后台接口
            selectExpertCount(userInfo.id).then(res => {
                this.info = res.data.data
                this.handleData(this.info)
            })
        }
    },
    handleData(info) {
        // 诊断统计
        for (var i = 0; i < info.mtc.length; i++) {
            this.total_cg.push(this.info.mtc[i].cgtotal)
            this.total_bd.push(this.info.mtc[i].bdtotal)
            this.total_xb.push(this.info.mtc[i].xbtotal)
            this.total_hz.push(this.info.mtc[i].hztotal)
        }
        this.total_cg.push(0)
        this.total_bd.push(0)
        this.total_xb.push(0)
        this.total_hz.push(0)
        // 大体取材统计
        for (varj = 0; j < info.dtqc.length; j++) {
            this.dtqc_total.push(info.dtqc[j].total)
        }

        // 顶部数据
        for (var a = 0; a < info.ptc.length; a++) {
            if (info.ptc[a].pathologyType === 7) {
                Object.assign(this.cg, this.cg, info.ptc[a])
            } else if (info.ptc[a].pathologyType === 8) {
                Object.assign(this.xb, this.xb, info.ptc[a])
            } else if (info.ptc[a].pathologyType === 9) {
                Object.assign(this.bd, this.bd, info.ptc[a])
            } else {
                Object.assign(this.hz, this.hz, info.ptc[a])
            }
        }

        // 受邀

        for (varb\ = 0; b < info.intc.length; b++) {
            if (info.intc[b].pathologyType === 7) {
                this.cg.sy = info.ptc[b].sy
            } else if (info.intc[b].pathologyType === 8) {
                this.xb.sy = info.ptc[b].sy
            } else if (info.intc[b].pathologyType === 9) {
                this.bd.sy = info.intc[b].sy
            } else {
                this.cg.sy = info.intc[b].sy
            }
        }
    },
阅读 10.8k
2 个回答

你的this.cg是一个对象,你这样写vue是监听不到数据的变化的
需要使用 this.$set 方法,或者

newobj = this.cg
newobj.sy = sy
this.cg = _.clone(newobj) 

这样完全重新赋值才行

撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题