3

I want to make a page refresh after I click on the router-link. How can I do that with Vue JS in Laravel? but I don't want to use onclick="window.location.reload();"

My code is something like that-

Code in app.js

{
    path: '/publisher',
    component: require('./components/Publishers.vue').default,
  }

Code in Master.blade.php

<li> <router-link to="/publisher" class="nav-link"  >انتشارات</router-link></li>

Code in publishers.vue

export default {
  components: {  
  },
  data() {
    return {
     
      Publishers: {},
     
    };
  },
  computed: {},
  methods: {    
    loadPublishers() {
      this.$Progress.start();
      axios.get("api/publisher").then(({ data }) => (this.Publishers = data));
    },
  },

  created() {
    this.loadPublishers();
    // load the page after 3 secound
    Fire.$on("refreshPage", () => {
      this.loadPublishers();
    });
  }
};
4
  • 1
    "I don't want to use onclick="window.location.reload();"" 👈 why not? Commented Mar 30, 2020 at 3:41
  • I want to know what is used for it in vue Commented Mar 30, 2020 at 3:49
  • 1
    Vue is an un-opinionated UI framework. There is no "Vue version" of this sort of action. You can use whatever works Commented Mar 30, 2020 at 3:50
  • I have never used Laravel in my life and don't know anything about data table UI components. Commented Mar 30, 2020 at 3:54

1 Answer 1

7

You can add a name property to the route object and instead of using <router-link>, you can use an a tag like this

<a :href="$router.resolve({name: 'publisher'}).href">link</a>

Your route object will be like

{
    path: '/publisher',
    name: 'publisher',
    component: require('./components/Publishers.vue').default,
}

The name field in the router is not mandatory, it is using only for making it simple to use.

Sign up to request clarification or add additional context in comments.

2 Comments

Please check this link : matanya.gitbook.io/vue-tables-2 or you can try datatable in Vuetify (vuetifyjs.com/en/components/data-tables). I always use custom tables for my purpose ;)
Using a with $router works great (+1). It passes original route parameters as well. However, if different or additional parameter is required, use params, eg: <a :href="$router.resolve({name: 'routeName', params: {id: anotherId} }).href"

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.