Skip to content
Fix Code Error

Vuejs and Page Refresh on click

April 7, 2021 by Code Error
Posted By: Anonymous

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();
    });
  }
};

Solution

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.

Answered By: Anonymous

Related Articles

  • Reference — What does this symbol mean in PHP?
  • Failed to authenticate on SMTP server error using gmail
  • Failed to mount component on new laravel 5.5 project
  • getting error while updating Composer
  • Examples of GoF Design Patterns in Java's core libraries
  • Laravel blade template changing to vue component
  • Bootstrap 4 align navbar items to the right
  • Reference - What does this regex mean?
  • How to filter a RecyclerView with a SearchView
  • What is a NullReferenceException, and how do I fix it?
  • What's the difference between eval, exec, and compile?
  • How to implement sub menu of the current route's…
  • Center an element in Bootstrap 4 Navbar
  • Ukkonen's suffix tree algorithm in plain English
  • Difference between variable declaration syntaxes in…
  • How to implement a Navbar Dropdown Hover in Bootstrap v4?
  • Bootstrap4 adding scrollbar to div
  • Aurelia: How navigate between child routes
  • Identifying and solving…
  • What are the undocumented features and limitations…
  • For-each over an array in JavaScript
  • Vue&TypeScript: how to avoid error TS2345 when…
  • How to VueJS router-link active style
  • Good way of getting the user's location in Android
  • How does PHP 'foreach' actually work?
  • How do SO_REUSEADDR and SO_REUSEPORT differ?
  • How can I use/create dynamic template to compile…
  • commandButton/commandLink/ajax action/listener…
  • Download a file with Android, and showing the…
  • Programmatically navigate using react router V4
  • data.table vs dplyr: can one do something well the…
  • Stacked Tabs in Bootstrap 3
  • PHP parse/syntax errors; and how to solve them
  • Align nav-items to right side in bootstrap-4
  • What are the new features in C++17?
  • Understanding PrimeFaces process/update and JSF…
  • Vue.js page transition fade effect with vue-router
  • How to use Bootstrap-Vue with a custom navbar…
  • Vue: disable no-unused-vars error: the simplest fix
  • Decreasing height of bootstrap 3.0 navbar
  • How to paste yanked text into the Vim command line
  • Load json from local file with http.get() in angular 2
  • Usage of __slots__?
  • Dynamically change bootstrap progress bar value when…
  • How to use java.net.URLConnection to fire and handle…
  • How to hide collapsible Bootstrap 4 navbar on click
  • What is your most productive shortcut with Vim?
  • How to create and publish a Vuejs component on NPM
  • How do Mockito matchers work?
  • Why do I have to "git push --set-upstream origin "?
  • How to find out client ID of component for ajax…
  • What does "Fatal error: Unexpectedly found nil while…
  • Laravel 5 Vue hot module replacement (HMR)
  • Refresh Page and Keep Scroll Position
  • PHP - Failed to open stream : No such file or directory
  • How to generate a random string of a fixed length in Go?
  • Combining bootstrap-vue and vue-router inside navbar…
  • Pass props in Link react-router
  • Why call git branch --unset-upstream to fixup?
  • Why does Git say my master branch is "already up to…
  • ExpressJS How to structure an application?
  • Aurelia: child router routes display in "main"…
  • Display progress bar while doing some work in C#?
  • Delegation: EventEmitter or Observable in Angular
  • Vue component not showing up in laravel
  • Bootstrap nav pills for VueJS vue-router
  • In CSS Flexbox, why are there no "justify-items" and…
  • Getting error "Failed to mount component: template…
  • Vuejs route redirect on refresh
  • Vue.js 2.0 failed to compile template
  • Change navbar color in Twitter Bootstrap
  • Vue.js app no errors but white page
  • Backbone View function throws TypeError: object is…
  • How to dynamically change content of component with JSON?
  • How to detect page is refreshed on vue?
  • vue js cant understand keep alive
  • How to set up webpack-hot-middleware in an express app?
  • Get specific data from vuex store while using a route
  • Vue.prototype is undefined on first load of the page
  • Making axios global in Vue project is not working
  • ERROR Error: Uncaught (in promise), Cannot match any…
  • finally() not working in Vuejs another app
  • Why does C++ code for testing the Collatz conjecture…
  • javax.faces.application.ViewExpiredException: View…
  • Refreshing authentication tokens for a Vue.js SPA…
  • How to add a Vuejs component to a Laravel Spark application?
  • How do I install Java on Mac OSX allowing version switching?
  • Understanding what does Axios create do
  • Getting navigation duplicated error while the route…
  • What is an optional value in Swift?
  • How do I use namespaces with TypeScript external modules?
  • Why doesn't the height of a container element…
  • jQuery Mobile: document ready vs. page events
  • Axios is not sending cookies
  • Check synchronously if file/directory exists in Node.js
  • Git merge with force overwrite
  • What is the scope of variables in JavaScript?
  • Java string to date conversion
  • How to detect if multiple keys are pressed at once…
  • How can I view the source code for a function?

Disclaimer: This content is shared under creative common license cc-by-sa 3.0. It is generated from StackExchange Website Network.

Post navigation

Previous Post:

Nuxt.js Store, dispatch action to other store

Next Post:

How to change default ‘page’ Directory name or Location in nextjs?

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

Recent Posts

  • jest.fn() claims not to have been called, but has
  • I18Next doesn’t work when loading data from backend
  • Properly setting the context for an Ember partial rendered from within a template
  • Custom Backbone Sync
  • Vue-router page refresh or URL access
  • Vue.js – Unknown custom element:
  • server returning 302 moved on create in Rails
  • TypeError: Cannot call method ‘replace’ of null – Backbone.js
  • Capture div containing inline svg and download it as image
  • Overview of the Ember.js code
  • Polymer 1.0 – HIDE Paper Drawer Panel
  • How to get a backend error message on the frontend using Fetch
  • How to change day-format (M > Mo, F > Fr…) in Date/month pickers of Vuetify
  • Vue.js cache method outcome?
  • Vue, Vuetify – Reduce space between buttons in toolbar
  • How to get reference to google map object inside a VueJs component?
  • Parent onClick is not triggered when the child element is clicked inside button
  • “Error with Permissions-Policy header” getting after Chrome update
  • Ember.js passing parameters from views to controller functions
  • Trouble vertically centering a polymer element inside a fullbleed body

Categories Tags

.net (1074) ajax (457) android (2318) angularjs (553) arrays (1090) asp.net (630) backbone.js (2260) bash (760) c++ (4925) css (2466) date (485) datetime (471) ember.js (1278) excel (566) git (1084) html (3345) ios (701) java (4508) javascript (9389) jquery (2998) json (943) laravel (506) linux (797) list (561) mysql (1310) node.js (895) oracle (475) pandas (449) php (2230) python (4372) r (537) reactjs (545) regex (554) shell (517) sql (1847) sql-server (1217) string (1360) tsql (471) twitter-bootstrap (515) typescript (418) vue-component (715) vue.js (5161) vuejs2 (1675) vuetify.js (495) windows (590)
© 2021 Fix Code Error