V2EX = way to explore
V2EX 是一个关于分享和探索的地方
Sign Up Now
For Existing Member  Sign In
lebus
V2EX  ›  Vue.js

laravel,vue 怎么实现游客刷新之后,只显示点过赞的那条评论被点赞,而不要所有的评论都显示被点赞?

  •  1
     
  •   lebus · Mar 23, 2018 · 3031 views
    This topic created in 2969 days ago, the information mentioned may be changed or developed.

    用 vue 做的点赞和点踩组件。

    用的 localstorage 存储了游客用户是否已点赞(点赞就设定 isLike 为 1,取消点赞则移除 isLike ),刷新之前一切都好好的。 刷新之后,因为在 mounted 方法里面判断 localstorage 是否有值,有的话改变点赞按钮的状态(颜色,文本)。 结果:只要点过了一个评论的赞,所有的评论都显示被点过赞了。

    想再存一个被点赞的评论 id 进 localstorage 的,然后在 mounted 里面判断此评论 id 是否有值,但是这样每次都刷新了 localstorage 里面的值,所以只能显示其中一条被点过赞,不能显示几条。

    想了几天没想出来,请各位大神不吝赐教。

    mounted() {
            if(localStorage.getItem('isLike')==='1'){
                this.isLikeReview=true
            }else if(localStorage.getItem('isHate')==='1'){
                this.isHateReview=true
            }else if(this.is_login) {
                axios.get(`/reviews/${this.review}/like`)
                    .then(response => {
                        // console.log(response);
                        this.isLikeReview = response.data.is_like_review;
                    });
                axios.get(`/reviews/${this.review}/hate`)
                    .then(response => {
                        this.isHateReview = response.data.is_hate_review;
                    })
            }
        },
    
    No Comments Yet
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   2754 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 27ms · UTC 15:35 · PVG 23:35 · LAX 08:35 · JFK 11:35
    ♥ Do have faith in what you're doing.