Vue implements 3 ways to switch tabs and switch to maintain data status

Vue implements 3 ways to switch tabs and switch to maintain data status

3 ways to implement tab switching in Vue

1. v-show controls content switching

1. Simple version principle: Use click event to change num value as a switch to control tab style and content display and hiding.

Click to switch the Vue tab

2. Data rendering principle: mainly use the index bound by v-for to control, which is similar to the above.

for-tab

2. Component switching.

1. The main knowledge points are the characteristics of is in vue and keep-alive cache

Vue component switching

3. Route switching. (Friendly for address bar and data request)

This is accomplished through router-link.

vue tab switch keeps data status

When switching tabs on a page, since the component will be re-instantiated every time it is switched, we want the content in the tab to remain unchanged no matter how the page is switched, reducing page re-rendering and requests.

Implementation method: Use <keep-alive></keep-alive> to wrap the component

<el-tabs v-model="activeName" @tab-click="handleClick">
  <el-tab-pane label="Record">
    <keep-alive>
      <child1 v-if="isChildUpdate"></child1>
    </keep-alive>
  </el-tab-pane>
</el-tabs>

Jump to details on the list page, and keep the last operation status on the list page

This is achieved by loading router-view and setting the routing meta page to cache.

If router-view is nested in multiple layers, you may need to set up multiple layers, and then use beforeRouteLeave to listen to the route leaving and set whether to cache

// Jumping from other pages does not require caching of pages. Returning from the details page requires caching.

Summarize

This concludes this article about 3 ways to implement tab switching in Vue and how to maintain data status during switching. For more information about Vue tab switching methods, please search previous articles on 123WORDPRESS.COM or continue to browse the following related articles. I hope you will support 123WORDPRESS.COM in the future!

You may also be interested in:
  • Problems and solutions for using vue-router and v-if to implement tab switching
  • Vue implements the method example of tab routing switching component
  • Detailed explanation of using Vue to implement tab switching operation
  • Four ways to switch tab pages in VUE
  • How to switch tabs in Vue router

<<:  How to Monitor Linux Memory Usage Using Bash Script

>>:  Detailed explanation of new relational database features in MySQL 8.0

Recommend

Five ways to traverse JavaScript arrays

Table of contents 1. for loop: basic and simple 2...

Docker configuration Alibaba Cloud Container Service operation

Configuring Alibaba Cloud Docker Container Servic...

HTML Basics - Simple Example of Setting Hyperlink Style

*** Example of setting the style of a hyperlink a...

How to implement a lucky wheel game in WeChat applet

I mainly introduce how to develop a lucky wheel g...

Detailed process of changing apt source to Alibaba Cloud source in Ubuntu 18.04

Table of contents Preface: Ubuntu 18.04 changes a...

Detailed explanation of JavaScript clipboard usage

(1) Introduction: clipboard.js is a lightweight J...

30 Tips for Writing HTML Code

1. Always close HTML tags In the source code of p...

How to print highlighted code in nodejs console

Preface When the code runs and an error occurs, w...

Detailed explanation of moment.js time and date processing

Monday to Sunday time format conversion (Y --- ye...

How to use indexes to optimize MySQL ORDER BY statements

Create table & create index create table tbl1...

Login interface implemented by html+css3

Achieve results First use HTML to build a basic f...

Introduction to MySQL Connection Control Plugin

Table of contents 1. Introduction to the connecti...