当前位置:网站首页>Solve the problem that the tabbar navigation at the bottom of vantui does not correspond to the page (window.loading.hash)
Solve the problem that the tabbar navigation at the bottom of vantui does not correspond to the page (window.loading.hash)
2022-07-04 02:14:00 【Yangcy】
Catalog
Preface
One need is to use vant Bottom tabbr Components , collocation vueRouter, Implement route navigation . Custom icon required , And the selected icon should change the selected style .vantui It provides a routing mode tabbar Of , But it doesn't seem to support custom icons . So the method in the figure below is used :
After using , Find a problem , That is, if you enter the secondary page , That is to say, it does not include tabbar Component page , Then the currently selected tabbar Item is lost , Will change back to the default 0, So you must leave tabbar When the component is on the page , Remember the currently selected tabbar Item or determine the current route , Re initialize according to the route tabbar The corresponding active. Convenience , I chose the latter .
solve
created() {
/* Solve the problem of entering the secondary route and returning to the default selected home page tab The problem of */
const navBarActive = window.location.hash;
if(navBarActive.includes("#/home")){
this.active = 0;
} else if(navBarActive.includes("#/baike")){
this.active = 1;
} else if(navBarActive.includes("#/mall")){
this.active = 2;
} else if(navBarActive.includes("#/cart")){
this.active = 3;
} else if(navBarActive.includes("#/me")){
this.active = 4;
}
}
vue-router Is based on window.loaction Of hash Property to implement , So every time I go back to the main page , Including tabbar When the page of the component , Determine the address corresponding to the current page hash, And then one by one and the corresponding tabbar Compare the corresponding routes , If meet , Just select the corresponding tabbar term , That is to active assignment . The reason why it is not used here switch To judge , Because the page address may have parameters , So not directly navBarActive Make an equal judgment with the route , It's the relationship involved .
At the end
because vue-router Is based on window.location Of hash Attribute , So many routing related problems can be solved from window.location Starting with . Print out... On the console window.location:
You can see information about the current page address ,hash The attribute actually corresponds to the route of the corresponding page we configured , We can also go through window.location.href To change the page address .
边栏推荐
- The latest analysis of hoisting machinery command in 2022 and free examination questions of hoisting machinery command
- Network byte order
- C # learning notes: structure of CS documents
- Question C: Huffman tree
- Winter vacation daily question -- a single element in an ordered array
- Create real-time video chat in unity3d
- When tidb meets Flink: tidb efficiently enters the lake "new play" | tilaker team interview
- A. Div. 7
- Mysql to PostgreSQL real-time data synchronization practice sharing
- Node write API
猜你喜欢

Example 072 calculation of salary it is known that the base salary of an employee of a company is 500 yuan. The amount of software sold by the employee and the Commission method are as follows: Sales
![Measurement fitting based on Halcon learning [4] measure_ arc. Hdev routine](/img/3a/cf6285ae1c01bda42874eeca9fe5b1.jpg)
Measurement fitting based on Halcon learning [4] measure_ arc. Hdev routine

Advanced learning of MySQL -- Application -- index

Maximum entropy model

16. System and process information

MySQL workbench use

Bacteriostatic circle scanning correction template

LV1 previous life archives

Write the first CUDA program

Applet graduation project is based on wechat classroom laboratory reservation applet graduation project opening report function reference
随机推荐
Small program graduation project based on wechat examination small program graduation project opening report function reference
A fan summed up so many interview questions for you. There is always one you need!
Database concept and installation
Jerry's synchronous weather information to equipment [chapter]
[leetcode daily question] a single element in an ordered array
Méthode de calcul de la connexion MSSQL de la carte esp32c3
Intel's new GPU patent shows that its graphics card products will use MCM Packaging Technology
IPv6 experiment
A. Div. 7
Example 073 square sum value judgment programming requires the input of a and B, if a ²+ b ² If the result of is greater than 100, a is output ²+ b ² Value, otherwise output the result of a + B.
MySQL utilise la vue pour signaler les erreurs, Explicit / show ne peut pas être publié; Verrouillage des fichiers privés pour la table sous - jacente
C language black Technology: Archimedes spiral! Novel, interesting, advanced~
Push technology practice | master these two tuning skills to speed up tidb performance a thousand times!
Life cycle of instance variables, static variables and local variables
Pesticide synergist - current market situation and future development trend
Chain ide -- the infrastructure of the metauniverse
Properties of binary trees (numerical aspects)
All ceramic crowns - current market situation and future development trend
C learning notes: C foundation - Language & characteristics interpretation
Pyrethroid pesticide intermediates - market status and future development trend