Vue refreshes the vue page through routing

Source: Internet
Author: User

Vue refreshes the vue page through routing

Vue development mall project,

The requirements are as follows:

The shopping cart page jumps to the details page. The shopping cart page contains multiple components. Click settlement to go to the order page. When the order is returned, the shopping cart page is not refreshed. Because the shopping cart components are transmitted through the bus, the beforeDestroy method cannot be triggered when a page Jump (non-physical return) occurs.

 beforeDestroy() {  this.$root.Bus.$off('judge')  this.$root.Bus.$off('refreshDetail')  this.$root.Bus.$off('clearAll')  this.$root.Bus.$off('upDataCart') },

Helpless, destroy through beforeRouteLeave

 beforeRouteLeave(to, from, next) {  this.$root.Bus.$off('judge')  this.$root.Bus.$off('refreshDetail')  this.$root.Bus.$off('clearAll')  this.$root.Bus.$off('upDataCart')  next() },

Similarly, when the physical return fails to trigger the created method of the shopping cart, the $ on method of the bus cannot be triggered.

In the final analysis, refresh the page when the physical returns can solve this problem.

Train of Thought 1

  beforeRouteEnter(to, from, next) {   next(()=>{     window.location.reload()   })  },

This method seems to be feasible in theory, but the page will be overwhelmed,

Finally, I used train of thought 2.It seems to be a low method, but it solves the actual problem.

This. $ router. replace ({name: 'cart'}) // refresh returned. this. $ router. push ({path: '/order/order_sure', query: {sku: sku_str, cart: 'cart '}})

The current page is directed to the current page through the route replace before the page Jump to the order page, the return can be automatically refreshed, this method is not ideal, if you have a better way, please share

You can add the following code on the shopping cart page.

// Destroy the component and return the refresh deactivated () {this. $ destroy ()},

The above is all the content of this article. I hope it will be helpful for your learning and support for helping customers.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.