欧美一级特黄大片做受成人-亚洲成人一区二区电影-激情熟女一区二区三区-日韩专区欧美专区国产专区

SpringBoot/VUE中如何實(shí)現(xiàn)路由傳遞參數(shù)

這篇文章將為大家詳細(xì)講解有關(guān)Spring Boot/VUE中如何實(shí)現(xiàn)路由傳遞參數(shù),小編覺得挺實(shí)用的,因此分享給大家做個(gè)參考,希望大家閱讀完這篇文章后可以有所收獲。

讓客戶滿意是我們工作的目標(biāo),不斷超越客戶的期望值來(lái)自于我們對(duì)這個(gè)行業(yè)的熱愛。我們立志把好的技術(shù)通過有效、簡(jiǎn)單的方式提供給客戶,將通過不懈努力成為客戶在信息化領(lǐng)域值得信任、有價(jià)值的長(zhǎng)期合作伙伴,公司提供的服務(wù)項(xiàng)目有:申請(qǐng)域名、網(wǎng)絡(luò)空間、營(yíng)銷軟件、網(wǎng)站建設(shè)、鎮(zhèn)海網(wǎng)站維護(hù)、網(wǎng)站推廣。

在路由時(shí)傳遞參數(shù),一般有兩種形式,一種是拼接在url地址中,另一種是查詢參數(shù)。如:http://localhost:8080/router/tang/101?type=spor&num=12。下面根據(jù)代碼看一下,VUE 和 Spring Boot 中各自是如何處理傳遞和接受參數(shù)的。

Spring Boot
package com.tang.demo1.controller; 
import org.springframework.web.bind.annotation.*; 
@RestController 
public class RouterController { 
 @RequestMapping(path = {"/router/{name}/{classid}"}, method = RequestMethod.GET) 
 public String router(@PathVariable("name") String name 
 ,@PathVariable("classid") int classid 
 ,@RequestParam(value = "type", defaultValue = "news") String type 
 ,@RequestParam(value = "num", required = falsef) int num){ 
 // 訪問 http://localhost:8080/router/tang/101?type=spor&num=12 
 return name + classid + type + num; 
 } 
} 

在url路徑中的,被稱為pathVariable,查詢參數(shù)被稱為pequestParm。在controller中接受參數(shù),可以直接在方法里用了。

VUE

routes: [ 
 { 
 path: '/', 
 name: 'HomePage', 
 component: HomePage 
 }, 
 { 
 path: '/user/:id?/:type?', 
 name: 'User', 
 component: User 
 } 
 ]

首先在路由中配置url中需要傳遞的參數(shù),被稱為動(dòng)態(tài)路徑參數(shù)。以“:”開始,末尾的“?”表示為可選的參數(shù)。

<template> 
<div> 
 <p>user</p> 
 <router-link :to="'/user/' + item.id + '/' + item.type +'?name=' + item.type" :key="index" v-for="(item, index) in userList">{{item.name}}</router-link> 
 <div v-if="childName"> 
 <p>-----</p> 
{{childName}} 
 </div> 
</div> 
</template> 
<script> 
var list = [ 
 {'name': 'xiaoming', 
 'id': 123, 
 'type': 'vip'}, 
 {'name': 'gangzi', 
 'id': 456, 
 'type': 'common'} 
] 
export default { 
 data(){ 
 return { 
 userList: list, 
 childName: null 
 } 
 }, 
 watch: { 
 $route(){ 
 if(this.$route.params.id){ 
this.childName = this.$route.params.id +'//////' + this.$route.query.name; 
 }else{ 
 this.childName = null 
 } 
 } 
 }, 
 methods: { 
 }, 
 created() { 
 // this.$route.params為動(dòng)態(tài)路徑參數(shù) 
 if(this.$route.params.id){ 
// this.$route.params為查詢參數(shù) 
this.childName = this.$route.params.id +'//////' + this.$route.query.name; 
 }else{ 
 this.childName = null 
 } 
 }, 
 deactivated() { 
 console.log('deact') 
 }, 
 computed: { 
 }, 
 components: { 
 } 
}; 
</script>

vue中接受參數(shù)需要從routes實(shí)例中獲取,動(dòng)態(tài)路徑參數(shù)在params里,查詢參數(shù)在query里。

當(dāng)vue的動(dòng)態(tài)路徑組件處在激活狀態(tài)時(shí),如果改變動(dòng)態(tài)路徑參數(shù),那么寫在created()的方法將不會(huì)再次被調(diào)用,因?yàn)樵摻M件已經(jīng)創(chuàng)建好了。此時(shí),可以為$route添加一個(gè)watch,當(dāng)其發(fā)生變化時(shí),再獲取數(shù)據(jù)。

在路由時(shí)傳遞參數(shù),一般有兩種形式,一種是拼接在url地址中,另一種是查詢參數(shù)。如:http://localhost:8080/router/tang/101?type=spor&num=12。下面根據(jù)代碼看一下,VUE 和 Spring Boot 中各自是如何處理傳遞和接受參數(shù)的。

Spring Boot
package com.tang.demo1.controller; 
import org.springframework.web.bind.annotation.*; 
@RestController 
public class RouterController { 
 @RequestMapping(path = {"/router/{name}/{classid}"}, method = RequestMethod.GET) 
 public String router(@PathVariable("name") String name 
 ,@PathVariable("classid") int classid 
 ,@RequestParam(value = "type", defaultValue = "news") String type 
 ,@RequestParam(value = "num", required = falsef) int num){ 
 // 訪問 http://localhost:8080/router/tang/101?type=spor&num=12 
 return name + classid + type + num; 
 } 
}

在url路徑中的,被稱為pathVariable,查詢參數(shù)被稱為pequestParm。在controller中接受參數(shù),可以直接在方法里用了。

VUE

routes: [ 
 { 
 path: '/', 
 name: 'HomePage', 
 component: HomePage 
 }, 
 { 
 path: '/user/:id?/:type?', 
 name: 'User', 
 component: User 
 } 
 ]

首先在路由中配置url中需要傳遞的參數(shù),被稱為動(dòng)態(tài)路徑參數(shù)。以“:”開始,末尾的“?”表示為可選的參數(shù)。

<template> 
<div> 
 <p>user</p> 
 <router-link :to="'/user/' + item.id + '/' + item.type +'?name=' + item.type" :key="index" v-for="(item, index) in userList">{{item.name}}</router-link> 
 
 <div v-if="childName"> 
 <p>-----</p> 
{{childName}} 
 </div> 
</div> 
</template> 
<script> 
var list = [ 
 {'name': 'xiaoming', 
 'id': 123, 
 'type': 'vip'}, 
 {'name': 'gangzi', 
 'id': 456, 
 'type': 'common'} 
] 
export default { 
 data(){ 
 return { 
 userList: list, 
 childName: null 
 } 
 }, 
 watch: { 
 $route(){ 
 if(this.$route.params.id){ 
this.childName = this.$route.params.id +'//////' + this.$route.query.name; 
 }else{ 
 this.childName = null 
 } 
 } 
 }, 
 methods: { 
 
 }, 
 created() { 
 // this.$route.params為動(dòng)態(tài)路徑參數(shù) 
 if(this.$route.params.id){ 
// this.$route.params為查詢參數(shù) 
this.childName = this.$route.params.id +'//////' + this.$route.query.name; 
 }else{ 
 this.childName = null 
 } 
 
 }, 
 deactivated() { 
 console.log('deact') 
 }, 
 computed: { 
 
 }, 
 components: { 
 } 
}; 
</script>

vue中接受參數(shù)需要從routes實(shí)例中獲取,動(dòng)態(tài)路徑參數(shù)在params里,查詢參數(shù)在query里。

當(dāng)vue的動(dòng)態(tài)路徑組件處在激活狀態(tài)時(shí),如果改變動(dòng)態(tài)路徑參數(shù),那么寫在created()的方法將不會(huì)再次被調(diào)用,因?yàn)樵摻M件已經(jīng)創(chuàng)建好了。此時(shí),可以為$route添加一個(gè)watch,當(dāng)其發(fā)生變化時(shí),再獲取數(shù)據(jù)。

在路由時(shí)傳遞參數(shù),一般有兩種形式,一種是拼接在url地址中,另一種是查詢參數(shù)。如:http://localhost:8080/router/tang/101?type=spor&num=12。下面根據(jù)代碼看一下,VUE 和 Spring Boot 中各自是如何處理傳遞和接受參數(shù)的。

Spring Boot
package com.tang.demo1.controller; 
import org.springframework.web.bind.annotation.*; 
@RestController 
public class RouterController { 
 @RequestMapping(path = {"/router/{name}/{classid}"}, method = RequestMethod.GET) 
 public String router(@PathVariable("name") String name 
 ,@PathVariable("classid") int classid 
 ,@RequestParam(value = "type", defaultValue = "news") String type 
 ,@RequestParam(value = "num", required = falsef) int num){ 
 // 訪問 http://localhost:8080/router/tang/101?type=spor&num=12 
 return name + classid + type + num; 
 } 
}

在url路徑中的,被稱為pathVariable,查詢參數(shù)被稱為pequestParm。在controller中接受參數(shù),可以直接在方法里用了。

VUE

routes: [ 
 { 
 path: '/', 
 name: 'HomePage', 
 component: HomePage 
 }, 
 { 
 path: '/user/:id?/:type?', 
 name: 'User', 
 component: User 
 } 
 ]

首先在路由中配置url中需要傳遞的參數(shù),被稱為動(dòng)態(tài)路徑參數(shù)。以“:”開始,末尾的“?”表示為可選的參數(shù)。

<template> 
<div> <p>user</p> 
 <router-link :to="'/user/' + item.id + '/' + item.type +'?name=' + item.type" :key="index" v-for="(item, index) in userList">{{item.name}}</router-link> 
 <div v-if="childName"> 
 <p>-----</p> 
{{childName}} 
 </div> 
</div> 
</template> 
<script> 
var list = [ 
 {'name': 'xiaoming', 
 'id': 123, 
 'type': 'vip'}, 
 {'name': 'gangzi', 
 'id': 456, 
 'type': 'common'} 
] 
export default { 
 data(){ 
 return { 
 userList: list, 
 childName: null 
 } 
 }, 
 watch: { 
 $route(){ 
 if(this.$route.params.id){ 
this.childName = this.$route.params.id +'//////' + this.$route.query.name; 
 }else{ 
 this.childName = null 
 } 
 } 
 }, 
 methods: { 
 }, 
 created() { 
 // this.$route.params為動(dòng)態(tài)路徑參數(shù) 
 if(this.$route.params.id){ 
// this.$route.params為查詢參數(shù) 
this.childName = this.$route.params.id +'//////' + this.$route.query.name; 
 }else{ 
 this.childName = null 
 } 
 }, 
 deactivated() { 
 console.log('deact') 
 }, 
 computed: { 
 }, 
 components: { 
 } 
}; 
</script>

vue中接受參數(shù)需要從routes實(shí)例中獲取,動(dòng)態(tài)路徑參數(shù)在params里,查詢參數(shù)在query里。

當(dāng)vue的動(dòng)態(tài)路徑組件處在激活狀態(tài)時(shí),如果改變動(dòng)態(tài)路徑參數(shù),那么寫在created()的方法將不會(huì)再次被調(diào)用,因?yàn)樵摻M件已經(jīng)創(chuàng)建好了。此時(shí),可以為$route添加一個(gè)watch,當(dāng)其發(fā)生變化時(shí),再獲取數(shù)據(jù)。

關(guān)于“Spring Boot/VUE中如何實(shí)現(xiàn)路由傳遞參數(shù)”這篇文章就分享到這里了,希望以上內(nèi)容可以對(duì)大家有一定的幫助,使各位可以學(xué)到更多知識(shí),如果覺得文章不錯(cuò),請(qǐng)把它分享出去讓更多的人看到。

本文題目:SpringBoot/VUE中如何實(shí)現(xiàn)路由傳遞參數(shù)
文章網(wǎng)址:http://www.aaarwkj.com/article4/pjcsoe.html

成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供外貿(mào)建站、品牌網(wǎng)站建設(shè)、品牌網(wǎng)站制作、建站公司、定制網(wǎng)站、搜索引擎優(yōu)化

廣告

聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請(qǐng)盡快告知,我們將會(huì)在第一時(shí)間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如需處理請(qǐng)聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時(shí)需注明來(lái)源: 創(chuàng)新互聯(lián)

商城網(wǎng)站建設(shè)
午夜一区二区精品视频国产 | 国产精品久久久久精品三级中文国 | 日韩在线视频 一区二区三区| 日韩欧美麻豆不卡一区二区| 东京热一区二区电影| 日本一区不卡二区高清| 日韩在线一区二区三区电影| 欧美三级欧美一级视频看| 亚洲日本韩国福利久久| 亚洲精品色在线网站国产呦| 久久精品色一情一乱一伦| 日韩视频播放一区二区| 精品毛片在线播放网站不卡| 久久精品欧美日韩视频| 亚洲精品视频在线观看视频| 亚洲,日韩,欧美久久综合| 高清av在线国产成人精品自拍| 少妇人妻精品一区三区二区| 国产男女免费完整视频| 亚洲av午夜福利麻豆av | 亚洲国产精品第一区第二区| 亚洲av永久精品一区二区三区| 亚洲av不卡一区二区在线观看| 亚洲人午夜射精精品日韩| 国产午夜视频成人无遮挡| 国产精品国产三级国av中文 | 欧美日韩在线视频一区| 在线观看中文字幕不卡二区| 日日夜夜久久国产精品| 日本亚洲欧洲一区二区| 深夜释放自己污在线看| 白白色发布青青在线视频观看| 日进去了啊内射视频| 亚洲欧美精品成人一区| 免费一区二区三区黄色| 九九九热视频这里只有精品| 中文字幕日本人妻少妇| 国产成人大片一区二区三区| 日韩亚洲人成网站在线播放| 97全国免费观看视频| 国产麻豆三级在线观看|