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

Summary of how to modify the root password in MySQL 5.7 and MySQL 8.0

MySQL 5.7 version: Method 1: Use the SET PASSWORD...

js realizes the magnifying glass function of shopping website

This article shares the specific code of js to re...

Enabling and configuring MySQL slow query log

Introduction MySQL slow query log is an important...

Detailed explanation of Docker compose orchestration tool

Docker Compose Docker Compose is a tool for defin...

MySQL 8.0.3 RC is about to be released. Let’s take a look at the changes

MySQL 8.0.3 is about to be released. Let’s take a...

Common commands for mysql authorization, startup, and service startup

1. Four startup methods: 1.mysqld Start mysql ser...

MySQL trigger principle and usage example analysis

This article uses examples to explain the princip...

Implementation of tomcat deployment project and integration with IDEA

Table of contents 3 ways to deploy projects with ...

A brief discussion on the binary family of JS

Table of contents Overview Blob Blob in Action Bl...

A collection of common uses of HTML meta tags

What is a mata tag The <meta> element provi...

How to enable MySQL remote connection in Linux server

Preface Learn MySQL to reorganize previous non-MK...

Summary of CSS front-end knowledge points (must read)

1. The concept of css: (Cascading Style Sheet) Ad...

How to start/stop Tomcat server in Java

1. Project Structure 2.CallTomcat.java package co...