[Vuejs]-Vue.js route params data getting lost after the full page reload

0👍

Have you considered to put your id as a computed prop?
If you leave it in the component data, it will just update on create the component, and you can remove the watcher over $route, what is a higher operation than a computed property.

data(){
  return {
    user: {},
    thoughts: {},
  }
},
methods:{
 viewProfile() {
    // You can use destructuring here over your response
    axios.get('user_profile/' + this.id).then(({ data: { user_data, thoughts } }) => {
        this.user = user_data;
        this.thoughts = thoughts;
    }).catch(() => {

    });
},
computed: {
  id() {
    return this.$route.params.id;
  }
},
// because of the vue lifecycle hooks, this should be a `mounted` hook intead of a `created`
mounted() {
  this.viewProfile();
} 

0👍

sorry for the trouble mates i fixed the issue by changing some routes configurations. Really thankful for your efforts.There was a collision between my web routes and the vue routes which was solved.

Leave a comment