Home > Web Front-end > JS Tutorial > body text

How to implement Vue + Vue-router when the route switching data with the same name is not updated

小云云
Release: 2018-05-15 14:30:11
Original
2012 people have browsed it

This article mainly introduces the method of Vue + Vue-router routing switching data with the same name not to be updated. It has certain reference value. Interested friends can refer to it. I hope it can help everyone.

By default, switching between routes with the same name will not be executed because the component can be taken and placed in ready to obtain data. There are two ways to solve it

Note: This problem only exists in vue1

Method 1: Put the data acquisition under route.data~

route: {
  data({to: {params: { page }}}) {
    return Promise.all([
      this.getApi()
    ]).then(() => {

    })
  }
}
Copy after login

Method 2: Set route.canReuse = false, force the component not to be reused~

route: {
  canReuse() {
    return false
  }
},
ready() {
  var request = $.ajax({
    type: "POST",
    dataType: 'json',
    url: "api.php"
  });
  request.then((json) => {
    // balabala
  });
}
Copy after login

Related recommendations:

Build vue2 vue-router2 webpack3 engineering tutorial

vue-router routing basic instance sharing

vue-router implements tab page

The above is the detailed content of How to implement Vue + Vue-router when the route switching data with the same name is not updated. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!