[Vuejs]-How to push new data input to top on the list

0👍

Assuming your list simply loops through your comments array, you need to push the response at the first position of the list:

onSubmit() {
    this.showLoader = true
    this.form.post('add-comment')
        .then(response => {
            this.comments.unshift(response);
        });
},

This assumes that response is the actual comment (I can’t see into your form class).

0👍

<script>
    import Form from 'form-backend-validation';

    export default {
        data:() => ({
            form: new Form({
                article_id: null,
            }),        
        }),

        mounted() {
          this.fetch();  
        },

        methods: {
            async fetch() {
                const response = await this.form.post('add-comment');
                this.form.article_id = response.comment.article_id; 
            }
        }
    }
</script>

Please try this one.

Leave a comment