[Vuejs]-VueJS replace data of component // same route problem

0👍

Try to make your created as a watch

Something like:

watch: {
    '$route.params.searchTags': {
        deep: true,
        immediate: true, // this triggers the watch on component creation, so you can remove the created hook content
        handler() {
            if (!this.$route.params.searchTags) {
                this.getPosts(this.apiUrl);
            } else {
                this.getPostByTags('/getPostByTags', this.$route.params.searchTags);
            }
        }
    }
}

Leave a comment