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

Will CSS3 really replace SCSS?

When it comes to styling our web pages, we have t...

Solution to MySQL master-slave delay problem

Today we will look at why master-slave delay occu...

Measured image HTTP request

Please open the test page in a mainstream browser...

Mysql command line mode access operation mysql database operation

Usage Environment In cmd mode, enter mysql --vers...

Nginx 502 Bad Gateway Error Causes and Solutions

I have encountered the Nginx 502 Bad Gateway erro...

Introduction to JavaScript array deduplication and flattening functions

Table of contents 1. Array flattening (also known...

mysql installer community 8.0.12.0 installation graphic tutorial

This tutorial shares the installation of mysql in...

How to use node scaffolding to build a server to implement token verification

content Use scaffolding to quickly build a node p...

Detailed steps for installing and configuring MySQL 8.0 on CentOS

Preface Here are the steps to install and configu...

Quickly solve the problem of slow and stuck opening of input[type=file]

Why is it that when the input tag type is file an...

CSS sets the box container (div) height to always be 100%

Preface Sometimes you need to keep the height of ...

How to make your browser talk with JavaScript

Table of contents 1. The simplest example 2. Cust...