Fill modal with vue js

1

The problem:

I'm developing a site that has a feed with posts, each post has comments. When I click on the comment's button for the post, I need to upload a modal filled with comments and posting.

This part I can do, I just do not know how to use the watch function for modal react to change data , for example, when commenting on the publication modal), the watcher adds the comment on it.

Note: I have tried to use the watch, but since the modal is only populated when the user clicks the comments button, I do not know how to "initialize" the empty observer.

Where the data comes from:

The posts are in the store, when I click on comments, I call a function that passes the post to store and open the modal with the comments and the publication:

Function that places the clicked post on the store:

setOnCommentPost: function(post){
            this.$store.commit('setOnCommentPost',post);
            $("#commentPost").modal('show');
        }

Store:

state:{
    posts:{},        //Todos os posts do feed
    onCommentPost:{  //Post que esta atualmente no modal de comentários
        user:{},     //Usuário que postou
        comments:{}
    }
}

Component Script Remarks that is inside the modal component:

props:['action','method','user_auth'],
data: function(){
    return{
        post:{
            user:{},
            comments:{}
        }
    }
},
watch:{
    post: function(){
        this.post.comments = this.$store.getters.getOnCommentPost.comments
        this.post = this.$store.getters.getOnCommentPost
        this.post.user = this.$store.getters.getOnCommentPost.user
        this.post.likes = this.$store.getters.getOnCommentPost.likes
    }
}
    
asked by anonymous 26.12.2018 / 16:13

0 answers