当前位置:网站首页>Routing parameters
Routing parameters
2022-04-23 05:07:00 【Write poetry for you@】
Route parameters
1.query, String writing , Object writing
query The parameter is directly behind the path ? Add parameters
<router-link to="/Student/Xinxi/Detail?id=666&title= How do you do ">
news 01 </router-link>
The receiving party , By routing route, receive You can use interpolation syntax { {$route.query.xxx}}
But you have to transfer data dynamically , Such data is dead id=666,title=" How do you do "
therefore : ?key=value&key=value
<router-link :to="`/Student/Xinxi/Detail?id=${m.id}&title=${m.name}`">
<!-- : Add a colon and treat it all as js Expression to write `` It becomes a string again , But the template string has to be mixed with js Expression, so ${} -->
{
{m.name}} </router-link>
2.params Parameters , character string , Object writing
parmas Parameters Direct path / Parameters
params String writing
<router-link to="/Student/Xinxi/Detail/666/ How do you do ">
news 01 </router-link>
But the router doesn't know the last two of this route /666/ Hello, it's a parameter , So when configuring routing rules
should stay Xinxi( This last level of routing is there path Add a placeholder )
path: 'Xinxi/Detail/:id/:title' So the router knows the back The two parameters are not routing paths but parameters
params The writing method of parameter passing object
<router-link
v-bind:to="{
name:'Detail',
params:{
id:m.id,
name:m.name
}
}"
>
{
{m.name}}
</router-link>
ps: Note that there params The ginseng have to use name:"xxx" As the name of the component to jump to , Can't write path:/xx/xx/
The methods of parameter transmission can be divided into params Biography and reference query The ginseng , and params Chuan Shen can be divided into url Display parameters in , And not displaying parameters
1.params The ginseng ( Display parameters ), It can also be divided into declarative , And programming
~ declarative router-link: The way is through router-link Component's to Attribute implementation , The parameters of the sub route need to be configured in advance
<router-link to="/home/x">
Jump to sub route
</router-link>
{
path: '/child/:id',
component:Child
}
2. programmatic this.$router.push: It is also necessary to configure the parameters of the sub route in advance .
{
path: '/child/:id',
component:Child
}
this.$router.push({
path:'/child/${id}',
})
receive :this.$route.params.id
2.params The ginseng ( Do not display parameters ), It can also be divided into declarative , And programming , Unlike the display parameters , Here is the alias of routing name For value transfer
<router-link :to="{name:'Child',params:{id:1}}"> Jump to sub route </router-link>
{
path: '/child',
name: 'Child',
component: Child
}
this.$router.push({
name:'Child',
params:{
id: 1
}
})
4. Routing component delivery props The data is convenient for the routing component to receive
props Pass data to facilitate receiving routing components (detail) receive , Don't keep writing $route.query.xxx perhaps
yes $route.params.xxx, redundancy , Just write... In the configuration props:['xxx','xxx'], Then direct interpolation Syntax { {xxx}} You can use it.
The first way to write it :props Value as object , All... In this object key-value All combinations will eventually pass props Pass to Detail Components
for example : { component:Detail,props:{a:1,b:'hello'} }
This means to detail Routing component delivery props Parameters , And for the object , If received, it must be in this component
props:['a','b'] receive
The second way : Then route all received params Parameters through props Pass on to Detail Components
props:ture
It means that the received parameters are marked with props Form to Detail, Such as (id,title),
So in Detail Components can receive props:['id','title']
The third way :props The value is a function , Each set of objects returned by this function key-value Will pass props Pass to Detail Components ( Biography query,params)
props:function($route){ // This is a callback function , We define that we do not call , from vue-router call , And pass in the argument $route, We receive... In the form of formal parameters ??? It should be understood in this way
return {
id:$route.query.id,
title:$route.query.title,
a:1,
b:'xxxxx'
}
}
router And route difference
1.router yes VueRouter An object of , adopt Vue.use(VueRouter) and VueRouter Constructor gets a router Instance object of , This object is a global object , Contains all routes , Contains many key objects and attributes , for example history object ,
$router.push({path:'/path'}), The essence is to history Add a route to the stack , In our opinion, it's switching routes , But the essence is to add a histoty Record
$router.replace({path:'/path'}), Replace route , There is no history .
2.route It is a jump route object , Every route will have a route object , It's a local object , You can get the corresponding name,path,params,query etc. .
$route.path character string , Equal to the path of the current routing object , It will be resolved as an absolute path , Such as “/index/”
$route.params object , Contains the key value pairs of dynamic fragments and full matching fragments in the route
$route.query object , Contains key value pairs for query parameters in the route , for example , about /index?id=1, You'll get $route.query.id == 1.
Routing reference plane test questions
1. Routing parameters () Object writing ,path Can it be combined params Parameters used together ?
answer : When routing jump passes parameters , The object can be written as ,name、path form , But here's the thing ,path This kind of writing cannot be compared with params Parameters are used together
this.$router.push({path:'/search',params:{keyword:this.keyword},query:{k:this.keyword.toUpperCase()}})
},
2. How to specify params Parameters can be transferred or not ?
such as : When configuring routing parameters , Stand in position (params Parameters ), But when the route jumps, it will not be delivered , There will be problems with the path
If routing requires delivery params Parameters , But you just don't pass params Parameters , Find one thing ,url There will be problems. ,
How to specify params Parameters can be passed , Or not , When configuring routes , Put a question mark behind the station
{
path: '/search/:keyword?', /* The sub route is configured with parameters in advance */
component: Search,
meta:{show:true},
name:'search'
},
3.params Parameters can be passed or not , But if you pass an empty string , How to solve ?
Such as :
this.$router.push({ name:'search',params:{keyword:''},query:{k:this.keyword.toUpperCase()} })
Use undefined solve ,params Parameters can be passed 、 Don't deliver ( Empty string )
this.$router.push({ name:'search',params:{keyword:''||undefined},query:{k:this.keyword.toUpperCase()} })
版权声明
本文为[Write poetry for you@]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/04/202204220549552282.html
边栏推荐
- Kubectl command automatic replenishment
- Data security has become a hidden danger. Let's see how vivo can make "user data" armor again
- [winui3] Écrivez une copie du gestionnaire de fichiers Explorer
- Mac enters MySQL terminal command
- How can continuous integration (CI) / continuous delivery (CD) revolutionize automated testing
- Progress of innovation training (III)
- QPushButton slot function is triggered multiple times
- Leetcode 1547: minimum cost of cutting sticks
- 【数据库】MySQL基本操作(基操~)
- redis数据类型有哪些
猜你喜欢
Deep learning notes - object detection and dataset + anchor box
AQS源码阅读
[2021] Spatio-Temporal Graph Contrastive Learning
MySQL -- execution process and principle of a statement
AQS source code reading
Sword finger offer: the path with a certain value in the binary tree (backtracking)
Unique primary key ID of tidb sub table -- solution to failure of sequence and Gorm to obtain primary key
用LCR表完美测试无线充电系统中的线圈
Details related to fingerprint payment
数据安全问题已成隐患,看vivo如何让“用户数据”重新披甲
随机推荐
The 8 diagrams let you see the execution sequence of async / await and promise step by step
负载均衡简介
How can continuous integration (CI) / continuous delivery (CD) revolutionize automated testing
What are the redis data types
A trinomial expression that causes a null pointer
Cross border e-commerce | Facebook and instagram: which social media is more suitable for you?
TypeError: ‘Collection‘ object is not callable. If you meant to call the ......
退出vim的方法
Deep learning notes - semantic segmentation and data sets
静态流水线和动态流水线的区别认识
The 2021 more reading report was released, and the book consumption potential of post-95 and Post-00 rose
The WebService interface writes and publishes calls to the WebService interface (2)
信息学奥赛一本通 1212:LETTERS | OpenJudge 2.5 156:LETTERS
SCP command details
Installing kuberneters using kubedm
HRegionServer的详解
Docker installation and mysql5 7 installation
Informatics Aosai yibentong 1212: letters | openjudge 2.5 156: Letters
vscode ipynb文件没有代码高亮和代码补全解决方法
Sword finger offer: symmetric binary tree (recursive iteration leetcode 101)