十年網(wǎng)站開發(fā)經(jīng)驗(yàn) + 多家企業(yè)客戶 + 靠譜的建站團(tuán)隊(duì)
量身定制 + 運(yùn)營(yíng)維護(hù)+專業(yè)推廣+無(wú)憂售后,網(wǎng)站問(wèn)題一站解決
本篇內(nèi)容主要講解“Spring Boot/VUE中怎么實(shí)現(xiàn)路由傳遞參數(shù)”,感興趣的朋友不妨來(lái)看看。本文介紹的方法操作簡(jiǎn)單快捷,實(shí)用性強(qiáng)。下面就讓小編來(lái)帶大家學(xué)習(xí)“Spring Boot/VUE中怎么實(shí)現(xiàn)路由傳遞參數(shù)”吧!
創(chuàng)新互聯(lián)建站成都企業(yè)網(wǎng)站建設(shè)服務(wù),提供網(wǎng)站制作、網(wǎng)站建設(shè)網(wǎng)站開發(fā),網(wǎng)站定制,建網(wǎng)站,網(wǎng)站搭建,網(wǎng)站設(shè)計(jì),自適應(yīng)網(wǎng)站建設(shè),網(wǎng)頁(yè)設(shè)計(jì)師打造企業(yè)風(fēng)格網(wǎng)站,提供周到的售前咨詢和貼心的售后服務(wù)。歡迎咨詢做網(wǎng)站需要多少錢:18980820575
在路由時(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){ // 訪問(wèn) 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ù)。
user
{{item.name}} -----
{{childName}}
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){ // 訪問(wèn) 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ù)。
user
{{item.name}} -----
{{childName}}
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){ // 訪問(wèn) 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ù)。
user
{{item.name}} -----
{{childName}}
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ù)。
到此,相信大家對(duì)“Spring Boot/VUE中怎么實(shí)現(xiàn)路由傳遞參數(shù)”有了更深的了解,不妨來(lái)實(shí)際操作一番吧!這里是創(chuàng)新互聯(lián)網(wǎng)站,更多相關(guān)內(nèi)容可以進(jìn)入相關(guān)頻道進(jìn)行查詢,關(guān)注我們,繼續(xù)學(xué)習(xí)!