当前位置:网站首页>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
- 2022 electrician (elementary) examination question bank and electrician (elementary) simulation examination question bank
- Winter vacation daily question -- a single element in an ordered array
- Override and virtual of classes in C #
- Sword finger offer 14- I. cut rope
- Conditional statements of shell programming
- Write the first CUDA program
- Idea if a class cannot be found, it will be red
- Final consistency of MESI cache in CPU -- why does CPU need cache
- Chain ide -- the infrastructure of the metauniverse
猜你喜欢
When tidb meets Flink: tidb efficiently enters the lake "new play" | tilaker team interview
Should enterprises start building progressive web applications?
Iclr2022 | ontoprotein: protein pre training integrated with gene ontology knowledge
Applet graduation project based on wechat selection voting applet graduation project opening report function reference
Huawei cloud micro certification Huawei cloud computing service practice has been stable
IPv6 experiment
On Valentine's day, I code a programmer's exclusive Bing Dwen Dwen (including the source code for free)
Conditional statements of shell programming
C # learning notes: structure of CS documents
Ai aide à la recherche de plagiat dans le design artistique! L'équipe du professeur Liu Fang a été embauchée par ACM mm, une conférence multimédia de haut niveau.
随机推荐
Keep an IT training diary 055- moral bitch
What are the main investment products of bond funds and what are they
Data collection and summary
Basic editing specifications and variables of shell script
Méthode de calcul de la connexion MSSQL de la carte esp32c3
Mobile phone battery - current market situation and future development trend
What is the student party's Bluetooth headset recommendation? Student party easy to use Bluetooth headset recommended
Small program graduation project based on wechat e-book small program graduation project opening report function reference
LV1 Roche limit
Pesticide synergist - current market situation and future development trend
Douban scoring applet Part-3
After listening to the system clear message notification, Jerry informed the device side to delete the message [article]
In yolov5, denselayer is used to replace focus, and the FPN structure is changed to bi FPN
Yyds dry goods inventory override and virtual of classes in C
Ceramic metal crowns - current market situation and future development trend
Learn these super practical Google browser skills, girls casually flirt
Small program graduation project based on wechat examination small program graduation project opening report function reference
Software product download collection
ZABBIX API pulls the values of all hosts of a monitoring item and saves them in Excel
Take you to master the formatter of visual studio code