0

this.$store.state数据改变后, computed未生效, 困惑了很久, 不知道哪里出了问题...感谢您的阅读和解答.

1、computed

    computed: {
        msgInfo() {
            for (var i in this.$store.state.msgList.groupMsg) {
                if (this.$store.state.msgList.groupMsg[i].tid == this.$route.query.tid) {
                    return this.$store.state.msgList.groupMsg[i]
                }
            }
        }
    },

2、模板调用

       <div class="row clearfix" v-for="item in msgInfo.msg" :key="item.mid">
            <img :src="item.headerUrl" class="header">
            <div class="content">
                <div class="content-header" style="height:10px;">
                    <p style="float:left;">{{item.fromname}}</p>
                    <p style="float:right;">{{item.createtime}}</p>
                </div>
                <div class="clear"></div>
                <p class="text" v-more>{{item.content}}</p>
                <div class="content-footer">
                    <p style="float:right;">--来自: {{item.groupname}}</p>
                </div>
                <div class="clear"></div>
            </div>
        </div>

3、数据变更

        var has = this.$store.state.msgList.groupMsg.some((item, index, array) => {
            if(item.tid == data.tid){
                this.$store.state.msgList.groupMsg[index].nexttime = data.create_time;
                this.$store.state.msgList.groupMsg[index].msg.push({
                    group : data.group,
                    groupname : data.groupname,
                    robotid : data.rid,
                    mid : data.mid,
                    from : data.from,
                    fromname : data.fromname,
                    content : data.content,
                    headerUrl : "http://q.qlogo.cn/headimg_dl?bs=qq&dst_uin=" + data.from + "&fid=blog&spec=100",
                    createtime : data.create_time
                });
                return true;
            }
        });
        
小恩 4
2019-05-17 提问

查看全部 2 个回答

1

已采纳

想要vue检测到引用类型内部的数据变化需要使用setdelete

推广链接