Complete step record of vue encapsulation TabBar component

Complete step record of vue encapsulation TabBar component

Implementation ideas:

Step 1: Component encapsulation of TabBar and TabBarItem

At this point, you can find that the basic layout of the page has been implemented, but the active state of the item click has not been implemented.

Step 2: Pass the active image to TabBarItem

In order to prevent the replaced content from directly replacing the entire slot, so that the style defined on the slot is also affected by the replacement, it is best to define a div wrapper outside the slot

Step 3: The combination of TabBarItem and routing

Step 4: TabBarItem color control

It is basically completed, but it is found that the repeated click path in the route will result in an error

Cause of error:

This is because the callback format of vue-router ≥ 3.0 is changed to promise. If no error is caught, this kind of error warning will appear in the console.

Solution 1: Downgrade vue-router to version 3.0

Solution 2:

Rewrite the push and replace methods on the Router prototype chain so that you don't have to add a catch every time you call the method.

Write the following content in main.js:

import Router from 'vue-router'
 
const originalPush = Router.prototype.push
Router.prototype.push = function push(location, onResolve, onReject) {
  if (onResolve || onReject) return originalPush.call(this, location, onResolve, onReject)
  return originalPush.call(this, location).catch(err => err)
}

If the push modification still does not take effect, you can try the replace method, for example:

const originalReplace = Router.prototype.replace;
Router.prototype.replace = function replace(location) {
  return originalReplace.call(this, location).catch(err => err);
};

Implemented with font icons

Introducing font icons

use

Summarize

This is the end of this article about vue encapsulation of TabBar component. For more relevant vue encapsulation of TabBar component content, please search 123WORDPRESS.COM's previous articles or continue to browse the following related articles. I hope everyone will support 123WORDPRESS.COM in the future!

You may also be interested in:
  • Vue implements the method example of tab routing switching component
  • Encapsulation practice example of Vue.js mobile tab component
  • Detailed explanation of how to use the Vue component tabbar
  • Vue encapsulates a Tabbar component with component routing jump method

<<:  HTML table border control implementation code

>>:  4 flexible Scss compilation output styles

Recommend

Detailed explanation of CSS image splicing technology (sprite image)

CSS image splicing technology 1. Image stitching ...

MySQL uses the truncate command to quickly clear all tables in a database

1. Execute the select statement first to generate...

How to configure Linux to use LDAP user authentication

I am using LDAP user management implemented in Ce...

Detailed example of jQuery's chain programming style

The implementation principle of chain programming...

Getting Started: A brief introduction to HTML's basic tags and attributes

HTML is made up of tags and attributes, which are...

Vue implements simple notepad function

This article example shares the specific code of ...

JavaScript implements simple calculator function

This article example shares the specific code of ...

Graphic tutorial on installing tomcat8 on centos7.X Linux system

1. Create the tomcat installation path mkdir /usr...

A brief discussion on the synchronization solution between MySQL and redis cache

Table of contents 1. Solution 1 (UDF) Demo Case 2...

Use pure CSS to disable the a tag in HTML without JavaScript

In fact, this problem has already popped up when I...

Implementation of importing and exporting vue-element-admin projects

vue-element-admin import component encapsulation ...

Design of pop-up windows and floating layers in web design

In the trend of gradual transition from tradition...

Websocket+Vuex implements a real-time chat software

Table of contents Preface 1. The effect is as sho...