Apply provide and inject to refresh Vue page method

Apply provide and inject to refresh Vue page method

Method 1: Call the function directly

Reload the entire page. Either of the following will work:

1.window.location.reload()

2. this.$router.go()

Method 2: Use provide / inject (static refresh)

Declare a reload refresh function in the higher-order function

<template>
  <div id="app" v-if="show"></div>
</template>
<script>
export default {
  //Control display/hide, implement refresh data () {
    return {
      show: true
    }
  },
  // Pass the refresh method to the low-level component provide () {
    return {
      reload: this.reload
    }
  },
  methods: {
    // High-level component defines refresh method reload () {
      this.bol = false
      this.$nextTick(() => {
        this.bol = true
      })
    }
  }
}
</script>

Using refresh functions in low-level components

<template>
  <div></div>
</template>
<script>
export default {
  inject: ['reload'],
  methods: {
    // Low-level component, refresh fun () {
      this.reload()
    }
  }
}
</script>

Advantages Comparison

  • Directly calling the function in method 1 will cause the entire website to refresh, which will waste performance and provide a poor user experience. For large websites, you will need to wait a few seconds for the refresh animation to appear in the upper left corner of the browser.
  • Method 2 uses provide / inject, so users will not feel the refresh, and the refreshed page content range can be controlled, which will waste less performance.

The above is the details of the method of applying provide and inject to refresh the Vue page. For more information about Vue page refresh, please pay attention to other related articles on 123WORDPRESS.COM!

You may also be interested in:
  • Learning and using provide/inject in Vue
  • Example of how to implement responsive data update using provide/inject in Vue.js
  • Use of provide and inject in Vue3
  • How to use [provide/inject] in Vue to implement page reload
  • Three ways to refresh the current page in the Vue project
  • Talk about the detailed application of provide/inject in Vue

<<:  Detailed explanation of root directory settings in nginx.conf

>>:  Which one should I choose between MySQL unique index and normal index?

Recommend

MySQL cursor principle and usage example analysis

This article uses examples to explain the princip...

Vue custom v-has instruction, steps for button permission judgment

Table of contents Application Scenario Simply put...

Basic learning and experience sharing of MySQL transactions

A transaction is a logical group of operations. E...

How to upload projects to Code Cloud in Linux system

Create a new project test1 on Code Cloud Enter th...

CSS navigation bar menu with small triangle implementation code

Many web pages have small triangles in their navi...

WeChat applet records user movement trajectory

Table of contents Add Configuration json configur...

Summary of some points to note when registering Tomcat as a service

Here are some points to note when registering Tom...

Detailed explanation of CSS text decoration text-decoration &amp; text-emphasis

In CSS, text is one of the most common things we ...

Vue uses echart to customize labels and colors

This article example shares the specific code of ...

Analysis of implicit bug in concurrent replication of MySQL 5.7

Preface Most of our MySQL online environments use...

React concurrent function experience (front-end concurrent mode)

React is an open-source JavaScript library used b...

Detailed explanation of how to implement secondary cache with MySQL and Redis

Redis Introduction Redis is completely open sourc...

Javascript common higher-order functions details

Table of contents 1. Common higher-order function...

How to implement scheduled backup of CentOS MySQL database

The following script is used for scheduled backup...