当前位置:网站首页>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 .
边栏推荐
- Buuctf QR code
- Reading notes - learn to write: what is writing?
- Global and Chinese market of box seals 2022-2028: Research Report on technology, participants, trends, market size and share
- Applet graduation design is based on wechat course appointment registration. Applet graduation design opening report function reference
- Format character%* s
- Measurement fitting based on Halcon learning [4] measure_ arc. Hdev routine
- 在尋求人類智能AI的過程中,Meta將賭注押向了自監督學習
- Méthode de calcul de la connexion MSSQL de la carte esp32c3
- Design and implementation of redis 7.0 multi part AOF
- Small program graduation design is based on wechat order takeout small program graduation design opening report function reference
猜你喜欢

What are the advantages and disadvantages of data center agents?

17. File i/o buffer

Will the memory of ParticleSystem be affected by maxparticles

Introduction to graphics: graphic painting (I)

Advanced learning of MySQL -- Application -- index

MySQL advanced (Advanced) SQL statement (I)

Basic editing specifications and variables of shell script

Gee import SHP data - crop image

Comment la transformation numérique du crédit d'information de la Chine passe - t - elle du ciel au bout des doigts?
![Jerry's synchronous weather information to equipment [chapter]](/img/a9/e09bbf62161ea8ba60b0fce3fb5f89.jpg)
Jerry's synchronous weather information to equipment [chapter]
随机推荐
Will the memory of ParticleSystem be affected by maxparticles
Global and Chinese markets for electroencephalogram (EEG) devices 2022-2028: Research Report on technology, participants, trends, market size and share
Sequence sorting of basic exercises of test questions
Bacteriostatic circle scanning correction template
2022 R2 mobile pressure vessel filling certificate examination and R2 mobile pressure vessel filling simulation examination questions
Chapter 3.4: starrocks data import - Flink connector and CDC second level data synchronization
Chinese Mitten Crab - current market situation and future development trend
Summarize the past to motivate yourself to move on
Format character%* s
Design and implementation of redis 7.0 multi part AOF
LeetCode 168. Detailed explanation of Excel list name
When the watch system of Jerry's is abnormal, it is used to restore the system [chapter]
FRP intranet penetration
Idea if a class cannot be found, it will be red
[typora installation package] old typera installation package, free version
Iclr2022 | ontoprotein: protein pre training integrated with gene ontology knowledge
mysql使用視圖報錯,EXPLAIN/SHOW can not be issued; lacking privileges for underlying table
Small program graduation design is based on wechat order takeout small program graduation design opening report function reference
Yyds dry goods inventory override and virtual of classes in C
String: LV1 eat hot pot