国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 編程 > JavaScript > 正文

詳解vue嵌套路由-query傳遞參數(shù)

2019-11-19 16:31:24
字體:
供稿:網(wǎng)友

在嵌套路由中我們經(jīng)常會遇到父路由向子路由里面?zhèn)鬟f參數(shù),傳遞參數(shù)有兩種方法,通過 query 或者 params

index.html

<div id="app">   <!-- router-view 路由出口, 路由匹配到的組件將渲染在這里 -->   <router-view></router-view> </div> 

main.js 同樣通過重定向來顯示父路由

import Vue from 'vue' import VueRouter from 'vue-router' Vue.use(VueRouter)  //引入兩個組件 import home from "./home.vue" import game from "./game.vue" //定義路由 const routes = [   { path: "/", redirect: "/home" },//重定向   {     path: "/home", component: home,     children: [       { path: "/home/game", component: game }     ]   } ] //創(chuàng)建路由實例 const router = new VueRouter({routes})  new Vue({   el: '#app',   data: {     id:123,   },   methods: {    },   router }) 

home.vue 通過query來傳遞num參數(shù)為1,相當與在 url 地址后面拼接參數(shù)

<template>   <div>     <h3>首頁</h3>     <router-link :to="{ path:'/home/game', query: { num: 1} }">       <button>顯示<tton>     </router-link>      <router-view></router-view>   </div> </template> 

game.vue 子路由中通過 this.$route.query.num 來顯示傳遞過來的參數(shù)

<template>   <h3>王者榮耀{{ this.$route.query.num }}</h3> </template>

運行后的結(jié)果,傳遞的參數(shù)在地址欄中有顯示

以上就是本文的全部內(nèi)容,希望對大家的學習有所幫助,也希望大家多多支持武林網(wǎng)。

發(fā)表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發(fā)表
主站蜘蛛池模板: 高平市| 博乐市| 河津市| 卓资县| 犍为县| 普兰县| 吉木萨尔县| 马边| 商都县| 穆棱市| 怀柔区| 西乌珠穆沁旗| 南投市| 康保县| 连南| 民和| 通许县| 抚州市| 和林格尔县| 湘潭市| 临沧市| 蕉岭县| 台中县| 邻水| 滨海县| 商水县| 英德市| 平昌县| 同仁县| 巩留县| 张掖市| 诸城市| 宜兴市| 珲春市| 黑水县| 铁岭县| 株洲县| 营山县| 澄城县| 太谷县| 睢宁县|