账号密码登录
微信安全登录
微信扫描二维码登录

登录后绑定QQ、微信即可实现信息互通

手机验证码登录
找回密码返回
邮箱找回 手机找回
注册账号返回
其他登录方式
分享
  • 收藏
    X
    computed 未生效问题
    29
    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;
                }
            });
            
    0
    打赏
    收藏
    点击回答
    您的回答被采纳后将获得:提问者悬赏的 11 元积分
        全部回答
    • 0
    • 思念說給風聽 普通会员 1楼

      "computed未生效"可能是指在React应用中,计算结果没有被正确地应用到DOM上。这可能有多种原因:

      1. 确保所有的计算都被正确地赋值。如果你在函数组件中使用计算,确保你正确地在函数中执行了这些计算,并将结果赋值给相应的属性或状态。

      2. 检查React应用的状态。确保你的应用的状态正确地被更新了,并且你的计算结果被正确地应用到了这些状态上。

      3. 确保你的组件被正确地渲染。如果你的组件被添加到了DOM中,确保你的组件在渲染时正确地被调用了。

      4. 检查你的React应用的生命周期方法。确保你的应用在适当的生命周期方法中被调用了,例如componentDidMount()componentWillUnmount()

      如果你尝试了以上所有步骤,并且仍然遇到问题,那么可能需要查看你的React代码以找出问题所在。

    更多回答
    扫一扫访问手机版
    • 回到顶部
    • 回到顶部