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

Discussion on horizontal and vertical centering of elements in HTML

When we design a page, we often need to center th...

JS Decorator Pattern and TypeScript Decorators

Table of contents Introduction to the Decorator P...

How to set background blur with CSS

When making some pages, in order to make the page...

How to install mysql database in deepin 2014 system

Deepin 2014 download and installation For downloa...

HTML head structure

The following introduces the commonly used head s...

How to use React forwardRef and what to note

Previously, react.forwardRef could not be applied...

MySQL process control IF(), IFNULL(), NULLIF(), ISNULL() functions

In MySQL, you can use IF(), IFNULL(), NULLIF(), a...

Selection and thinking of MySQL data backup method

Table of contents 1. rsync, cp copy files 2. sele...

Install multiple versions of PHP for Nginx on Linux

When we install and configure the server LNPM env...

MySQL password modification example detailed explanation

MySQL password modification example detailed expl...

Element Plus implements Affix

Table of contents 1. Component Introduction 2. So...

A quick guide to Docker

Docker provides a way to automatically deploy sof...

Advantages and disadvantages of common MySQL storage engines

Table of contents View all storage engines InnoDB...