<span id="mktg5"></span>

<i id="mktg5"><meter id="mktg5"></meter></i>

        <label id="mktg5"><meter id="mktg5"></meter></label>
        最新文章專題視頻專題問答1問答10問答100問答1000問答2000關鍵字專題1關鍵字專題50關鍵字專題500關鍵字專題1500TAG最新視頻文章推薦1 推薦3 推薦5 推薦7 推薦9 推薦11 推薦13 推薦15 推薦17 推薦19 推薦21 推薦23 推薦25 推薦27 推薦29 推薦31 推薦33 推薦35 推薦37視頻文章20視頻文章30視頻文章40視頻文章50視頻文章60 視頻文章70視頻文章80視頻文章90視頻文章100視頻文章120視頻文章140 視頻2關鍵字專題關鍵字專題tag2tag3文章專題文章專題2文章索引1文章索引2文章索引3文章索引4文章索引5123456789101112131415文章專題3
        問答文章1 問答文章501 問答文章1001 問答文章1501 問答文章2001 問答文章2501 問答文章3001 問答文章3501 問答文章4001 問答文章4501 問答文章5001 問答文章5501 問答文章6001 問答文章6501 問答文章7001 問答文章7501 問答文章8001 問答文章8501 問答文章9001 問答文章9501
        當前位置: 首頁 - 科技 - 知識百科 - 正文

        Spring Boot/VUE中路由傳遞參數的實現代碼

        來源:懂視網 責編:小采 時間:2020-11-27 22:18:17
        文檔

        Spring Boot/VUE中路由傳遞參數的實現代碼

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

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

        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,查詢參數被稱為pequestParm。在controller中接受參數,可以直接在方法里用了。
        
        VUE
        
        routes: [ 
         { 
         path: '/', 
         name: 'HomePage', 
         component: HomePage 
         }, 
         { 
         path: '/user/:id?/:type?', 
         name: 'User', 
         component: User 
         } 
         ] 

        首先在路由中配置url中需要傳遞的參數,被稱為動態路徑參數。以“:”開始,末尾的“?”表示為可選的參數。

        <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為動態路徑參數 
         if(this.$route.params.id){ 
        // this.$route.params為查詢參數 
        this.childName = this.$route.params.id +'//////' + this.$route.query.name; 
         }else{ 
         this.childName = null 
         } 
         }, 
         deactivated() { 
         console.log('deact') 
         }, 
         computed: { 
         }, 
         components: { 
         } 
        }; 
        </script> 

        vue中接受參數需要從routes實例中獲取,動態路徑參數在params里,查詢參數在query里。

        當vue的動態路徑組件處在激活狀態時,如果改變動態路徑參數,那么寫在created()的方法將不會再次被調用,因為該組件已經創建好了。此時,可以為$route添加一個watch,當其發生變化時,再獲取數據。

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

        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,查詢參數被稱為pequestParm。在controller中接受參數,可以直接在方法里用了。

        VUE

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

        首先在路由中配置url中需要傳遞的參數,被稱為動態路徑參數。以“:”開始,末尾的“?”表示為可選的參數。

        <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為動態路徑參數 
         if(this.$route.params.id){ 
        // this.$route.params為查詢參數 
        this.childName = this.$route.params.id +'//////' + this.$route.query.name; 
         }else{ 
         this.childName = null 
         } 
         
         }, 
         deactivated() { 
         console.log('deact') 
         }, 
         computed: { 
         
         }, 
         components: { 
         } 
        }; 
        </script> 

        vue中接受參數需要從routes實例中獲取,動態路徑參數在params里,查詢參數在query里。

        當vue的動態路徑組件處在激活狀態時,如果改變動態路徑參數,那么寫在created()的方法將不會再次被調用,因為該組件已經創建好了。此時,可以為$route添加一個watch,當其發生變化時,再獲取數據。

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

        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,查詢參數被稱為pequestParm。在controller中接受參數,可以直接在方法里用了。

        VUE

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

        首先在路由中配置url中需要傳遞的參數,被稱為動態路徑參數。以“:”開始,末尾的“?”表示為可選的參數。

        <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為動態路徑參數 
         if(this.$route.params.id){ 
        // this.$route.params為查詢參數 
        this.childName = this.$route.params.id +'//////' + this.$route.query.name; 
         }else{ 
         this.childName = null 
         } 
         }, 
         deactivated() { 
         console.log('deact') 
         }, 
         computed: { 
         }, 
         components: { 
         } 
        }; 
        </script> 

        vue中接受參數需要從routes實例中獲取,動態路徑參數在params里,查詢參數在query里。

        當vue的動態路徑組件處在激活狀態時,如果改變動態路徑參數,那么寫在created()的方法將不會再次被調用,因為該組件已經創建好了。此時,可以為$route添加一個watch,當其發生變化時,再獲取數據。

        總結

        以上所述是小編給大家介紹的Spring Boot/VUE中路由傳遞參數的實現代碼,希望對大家有所幫助,如果大家有任何疑問請給我留言,小編會及時回復大家的。在此也非常感謝大家對腳本之家網站的支持!

        聲明:本網頁內容旨在傳播知識,若有侵權等問題請及時與本網聯系,我們將在第一時間刪除處理。TEL:177 7030 7066 E-MAIL:11247931@qq.com

        文檔

        Spring Boot/VUE中路由傳遞參數的實現代碼

        Spring Boot/VUE中路由傳遞參數的實現代碼:在路由時傳遞參數,一般有兩種形式,一種是拼接在url地址中,另一種是查詢參數。如:http://localhost:8080/router/tang/101?type=spor&num=12。下面根據代碼看一下,VUE 和 Spring Boot 中各自是如何處理傳遞和接受參數的。 Spring B
        推薦度:
        標簽: VUE 代碼 路由
        • 熱門焦點

        最新推薦

        猜你喜歡

        熱門推薦

        專題
        Top
        主站蜘蛛池模板: 亚洲av无码片区一区二区三区| 亚洲中文字幕日产乱码高清app| 亚洲精品无码久久毛片波多野吉衣| 三上悠亚电影全集免费| 亚洲国产精品成人久久蜜臀| 欧亚一级毛片免费看| 亚洲AⅤ视频一区二区三区| 中文字幕久无码免费久久| 亚洲国产V高清在线观看| 激情婷婷成人亚洲综合| mm1313亚洲精品无码又大又粗| 特黄aa级毛片免费视频播放| 免费一级毛片不卡不收费| 久久国产福利免费| 亚洲爱情岛论坛永久| 黄网站色在线视频免费观看| 国产成人精品亚洲2020| 国产青草视频免费观看97| 羞羞漫画登录页面免费| 久久亚洲国产精品123区| 久久精品国产免费一区| 亚洲理论精品午夜电影| 思思99re66在线精品免费观看| 爱爱帝国亚洲一区二区三区| 久久精品国产亚洲一区二区三区| 中文字幕无码一区二区免费| 亚洲精品偷拍无码不卡av| 国产精品自在自线免费观看| 九九视频高清视频免费观看 | 24小时日本在线www免费的| 亚洲欧美日韩中文字幕在线一区 | 亚洲精品成人网久久久久久| 一个人免费视频在线观看www | 亚洲成Av人片乱码色午夜| 在线成人爽a毛片免费软件| 亚洲精品无码国产片| 国产亚洲精aa成人网站| 114一级毛片免费| 曰批全过程免费视频免费看 | 亚洲国产成人精品不卡青青草原| 性做久久久久久免费观看|