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

Solve the problem of Vue routing change page data not refreshing

亚连
Release: 2018-05-30 17:27:39
Original
3150 people have browsed it

Below I will share with you an article that solves the problem of Vue routing change page data not refreshing. It has a good reference value and I hope it will be helpful to everyone.

Record a little bit every day and record the problems I encountered. I hope it can help more people who encounter the same problems as me.

Problem description: By adjusting the interface, the question list of the help page is dynamically displayed. The question list has multiple levels. When the clicked question does not have the next level question, it will jump to the content page.

The problem is that when I was making a mobile page on my computer, I jumped to the details page one after another. I wanted to go back and clicked the

button to jump directly to the first picture above. It looks like, no, no, no, this is not the result I want. At this moment, I thought of changing the hierarchy of the page by changing the URL.

The parent of the first level is 0, which is not displayed or displayed by default.

The parent of the second level is 1. Clicking on the first level route changes to the following figure:

When you click to enter the next level page, the data will be refreshed, but when you click on the computer to go back, the last URL of parent has changed to 1, and the page still displays the data of 2.

The solution is as follows:

created () {
 console.log(this.getStatus(this.$route.path))
},
 watch: {
 '$route' (to, from) {
  console.log(this.getStatus(this.$route.path))
 }
 },
 methods: {
 getStatus (urlStr) {
  var urlStrArr = urlStr.split('/')
  return urlStrArr[urlStrArr.length - 1]
 }
},
Copy after login

The above is what I compiled for everyone. I hope it will be helpful to everyone in the future.

Related articles:

How to introduce the icon icon into the Vue project

##E-mail address format verification in JavaScript

Introduction to time-sharing functions for javascript performance optimization

The above is the detailed content of Solve the problem of Vue routing change page data not refreshing. 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