路由传参和路由卫士

古城微笑少年丶 2021-08-19 15:06 614阅读 0赞

1.动态路由匹配

动态路由也可以叫做路由传参。
组件的显示内容经常会根据用户选择的内容不同来在同一个组件中渲染不同内容。那么在这个时候就需要动态路由。

1. 动态路径参数

  1. 使用动态路由匹配中的 动态路径参数来进行路由配置。
  2. 注意:动态路径参数 以冒号:开头

    {name:”tema”,path:”/index/:id/:name”,component:tema},

2. 绑定参数

  1. 路由导航绑定参数的两种方式 但是注意 params只能通过路由配置中的name属性来引用路由

    index
    home


    home

  2. js方式进行参数绑定

    fun() {

    1. // 对动态数据不太友好
    2. // this.$router.push("/home/呵呵哒/heheda")
    3. this.$router.push({
    4. name: 'home',
    5. //params只能通过name来引入路由
    6. params: {
    7. xiaoming: this.linktexta,
    8. xiaohong: this.linktextb
    9. }
    10. })

    }

3. 获取路由传入参数

  1. 如果想得到路径参数那么使用$route.params.id

  2. 或者是使用this实例中的this.$route.params.id进行调用

    created(){

    1. //路由信心都被挂载到实例中去
    2. console.log("路由参数是:"+this.$route.params.id+"---"+this.$route.params.name);

    }

params传参案例:

  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4. <meta charset="UTF-8">
  5. <meta name="viewport" content="width=device-width, initial-scale=1.0">
  6. <meta http-equiv="X-UA-Compatible" content="ie=edge">
  7. <title>Document</title>
  8. </head>
  9. <body>
  10. <!-- 动态路由匹配 路由传参 -->
  11. <!-- params的方式 -->
  12. <!-- 语法:1.需要配置路由规则 :传递数据的名字 -->
  13. <!-- 2.开始在导航中进行数据的传递 -->
  14. <!-- 3.接收传递的数据 this.$route.params.xxxx -->
  15. <div id="demodiv">
  16. <router-link to="/index">index</router-link>
  17. <!-- 2.在导航中进行数据的发送 -->
  18. <!-- 声明式导航 -->
  19. <!-- 2-1传递参数方式1 简单方便 对于传递动态数据不友好 -->
  20. <!-- <router-link to="/home/呵呵/哈哈">home</router-link> -->
  21. <!-- 2-2****推荐记忆推荐记忆*****传递方式2 语法稍微麻烦一些 但是对于动态数据非常友好 -->
  22. <!-- <router-link :to={name:"对应的是路由规则里面的你先去的那个页面的name",params:{路由规则绑定的数据名:你要传递的数据}}></router-link> -->
  23. <!-- <router-link :to="{name:'home',params:{xiaoming:linktexta,xiaohong:linktextb}}">home</router-link> -->
  24. <!-- 编程式导航 -->
  25. <!-- 2-3 -->
  26. <button @click="fun()">点我去home</button>
  27. <router-link to="/phone">phone</router-link>
  28. <router-link to="/user">user</router-link>
  29. <router-view></router-view>
  30. </div>
  31. <!-- 一级路由模板 -->
  32. <template id="tema">
  33. <div>
  34. <p @click="fun()">{
  35. {tematext}}</p>
  36. </div>
  37. </template>
  38. <template id="temb">
  39. <div>
  40. homehomehomehomehomehomehome{
  41. {this.$route.params.xiaoming}}----{
  42. {this.$route.params.xiaohong}}
  43. </div>
  44. </template>
  45. <template id="temc">
  46. <div>
  47. phonephonephonephonephonephonephone
  48. </div>
  49. </template>
  50. <template id="temd">
  51. <div>
  52. useruseruseruseruseruseruser
  53. <top-link></top-link>
  54. <router-view></router-view>
  55. </div>
  56. </template>
  57. <!-- 二级外部模板 -->
  58. <template id="ertema">
  59. <div>
  60. 我是二级路由11111111
  61. </div>
  62. </template>
  63. <template id="ertemb">
  64. <div>
  65. 我是二级路由2222222
  66. </div>
  67. </template>
  68. <template id="ertemc">
  69. <div>
  70. 我是二级路由333333333
  71. </div>
  72. </template>
  73. <template id="toplinktem">
  74. <div>
  75. <router-link to="/user/ertema">ertema</router-link>
  76. <router-link to="/user/ertemb">ertemb</router-link>
  77. <router-link to="/user/ertemc">ertemc</router-link>
  78. </div>
  79. </template>
  80. </body>
  81. </html>
  82. <script src="node_modules/vue/dist/vue.min.js"></script>
  83. <script src="node_modules/vue-router/dist/vue-router.js"></script>
  84. <script>
  85. // 1.为什么要把组件中的内容提取出来单独赋值给一个变量
  86. // 下面的是路由规则
  87. var tema = {
  88. template: "#tema",
  89. data() {
  90. return {
  91. tematext: "你好我是index中的变量数据"
  92. }
  93. },
  94. methods: {
  95. fun() {
  96. alert("我是index的函数")
  97. }
  98. },
  99. // created(){
  100. // alert("我是钩子函数")
  101. // }
  102. };
  103. var temb = {
  104. template: "#temb"
  105. };
  106. var temc = {
  107. template: "#temc"
  108. };
  109. var temd = {
  110. template: "#temd",
  111. components: {
  112. "topLink": {
  113. template: "#toplinktem"
  114. }
  115. }
  116. };
  117. // 二级路由的组件模板
  118. var ertema = {
  119. template: "#ertema"
  120. };
  121. var ertemb = {
  122. template: "#ertemb"
  123. };
  124. var ertemc = {
  125. template: "#ertemc"
  126. };
  127. var routes = [{
  128. name: "index",
  129. path: "/index",
  130. component: tema
  131. },
  132. // params传参1 配置路由规则
  133. {
  134. name: "home",
  135. path: "/home/:xiaoming/:xiaohong",
  136. component: temb
  137. },
  138. {
  139. name: "phone",
  140. path: "/phone",
  141. component: temc
  142. },
  143. {
  144. name: "user",
  145. path: "/user",
  146. component: temd,
  147. children: [{
  148. name: "ertema",
  149. path: "ertema",
  150. component: ertema
  151. },
  152. {
  153. name: "ertemb",
  154. path: "ertemb",
  155. component: ertemb
  156. },
  157. {
  158. name: "ertemc",
  159. path: "ertemc",
  160. component: ertemc
  161. }
  162. ]
  163. },
  164. {
  165. path: "/*",
  166. redirect: "/index"
  167. }
  168. ]
  169. var router = new VueRouter({
  170. routes
  171. })
  172. new Vue({
  173. el: "#demodiv",
  174. router,
  175. data: {
  176. linktexta: "我是第1个1数1据",
  177. linktextb: "我是第2个2数2据"
  178. },
  179. methods: {
  180. fun() {
  181. // 对动态数据不太友好
  182. // this.$router.push("/home/呵呵哒/heheda")
  183. this.$router.push({
  184. name: 'home',
  185. params: {
  186. xiaoming: this.linktexta,
  187. xiaohong: this.linktextb
  188. }
  189. })
  190. }
  191. }
  192. })
  193. </script>

query传参案例:

  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4. <meta charset="UTF-8">
  5. <meta name="viewport" content="width=device-width, initial-scale=1.0">
  6. <meta http-equiv="X-UA-Compatible" content="ie=edge">
  7. <title>Document</title>
  8. </head>
  9. <body>
  10. <!-- query传参
  11. 语法:
  12. 1.不需要配置路由规则
  13. 2.传参
  14. 3.接受
  15. -->
  16. <div id="demodiv">
  17. <router-link to="/index">首页</router-link>
  18. <!-- query传参方式 -->
  19. <!-- 1. -->
  20. <router-link to="/home?xiaoming=呵呵&xiaohong=哈哈">home</router-link>
  21. <!-- <router-link to="/home">小组</router-link> -->
  22. <router-link to="/phone">手机</router-link>
  23. <router-link to="/user">我的</router-link>
  24. <router-view></router-view>
  25. </div>
  26. <!-- 创建一级路由模板start -->
  27. <template id="tema">
  28. <div>
  29. <p @click="fun()">{
  30. {tematext}}</p>
  31. </div>
  32. </template>
  33. <template id="temb">
  34. <div>
  35. 接收传递过来的参数
  36. 小组{
  37. {this.$route.query.xiaoming}}======{
  38. {this.$route.query.xiaohong}}
  39. </div>
  40. </template>
  41. <template id="temc">
  42. <div>
  43. 手机
  44. </div>
  45. </template>
  46. <template id="temd">
  47. <div>
  48. 我的
  49. <toplink></toplink>
  50. <router-view></router-view>
  51. </div>
  52. </template>
  53. <!-- 创建一级路由模板end -->
  54. <!-- 创建二级路由模板start -->
  55. <template id="ertema">
  56. <div>
  57. 我是二级路由11111111
  58. </div>
  59. </template>
  60. <template id="ertemb">
  61. <div>
  62. 我是二级路由22222222
  63. </div>
  64. </template>
  65. <template id="ertemc">
  66. <div>
  67. 我是二级路由33333333
  68. </div>
  69. </template>
  70. <template id="ertemd">
  71. <div>
  72. 我是二级路由44444444
  73. </div>
  74. </template>
  75. <!-- 创建二级路由模板end -->
  76. <template id="toplinktem">
  77. <div>
  78. <router-link to="/user/ertema">ertema</router-link>
  79. <router-link to="/user/ertemb">ertemb</router-link>
  80. <router-link to="/user/ertemc">ertemc</router-link>
  81. <router-link to="/user/ertemd">ertemd</router-link>
  82. </div>
  83. </template>
  84. </body>
  85. </html>
  86. <script src="node_modules/vue/dist/vue.js"></script>
  87. <script src="node_modules/vue-router/dist/vue-router.js"></script>
  88. <script>
  89. // 创建一级路由模板组件start
  90. var tema = {
  91. template: "#tema",
  92. data(){
  93. return{
  94. tematext:"我是index中的变量数据"
  95. }
  96. },
  97. methods:{
  98. fun(){
  99. alert("我是index的函数")
  100. }
  101. }
  102. };
  103. var temb = {
  104. template: "#temb"
  105. };
  106. var temc = {
  107. template: "#temc"
  108. };
  109. var temd = {
  110. template: "#temd",
  111. components: {
  112. "topLink":{
  113. template:"#toplinktem"
  114. }
  115. }
  116. };
  117. // 创建一级路由模板组件end
  118. // 创建二级路由模板组件start
  119. var ertema = {
  120. template: "#ertema"
  121. };
  122. var ertemb = {
  123. template: "#ertemb"
  124. };
  125. var ertemc = {
  126. template: "#ertemc"
  127. };
  128. var ertemd = {
  129. template: "#ertemd"
  130. };
  131. // 创建二级路由模板组件end
  132. var routes = [{
  133. name: "index",
  134. path: "/index",
  135. component: tema
  136. },
  137. {
  138. name: "home",
  139. path: "/home",
  140. component: temb
  141. },
  142. {
  143. name: "phone",
  144. path: "/phone",
  145. component: temc
  146. },
  147. {
  148. name: "user",
  149. path: "/user",
  150. component: temd,
  151. children:[
  152. {name:"ertema",path:"ertema",component:ertema},
  153. {name:"ertemb",path:"ertemb",component:ertemb},
  154. {name:"ertemc",path:"ertemc",component:ertemc},
  155. {name:"ertemd",path:"ertemd",component:ertemd},
  156. {path:"/*",redirect: "/index"}
  157. ]
  158. },
  159. ]
  160. const router = new VueRouter({
  161. routes
  162. })
  163. new Vue({
  164. el:"#demodiv",
  165. data:{},
  166. router,
  167. data:{
  168. linktexta:"数据111111",
  169. linktextb:"数据222222"
  170. }
  171. })
  172. </script>
  1. params与query区别

    • 用法上的:
      params要用name来引入,接收参数都是类似的,分别是this. r o u t e . q u e r y . n a m e 和 t h i s . route.query.name和this. route.query.name和this.route.params.name。
    • url展示上的
      params类似于post,query更加类似于我们ajax中get传参,说的再简单一点,前者在浏览器地址栏中不显示参数,后者显示,所以params传值相对安全一些。

4. hash模式-history模式

hash模式url里面永远带着#号,我们在开发当中默认使用这个模式。

  1. history模式

    • history模式没有#号,是个正常的url适合推广宣传。
    • 考虑url的规范那么就需要使用history模式,因为当然其功能也有区别,在开发app的时候有分享页面,这个分享出去的页面就是用vue做的,把这个页面分享到第三方的app里,有的app里面url是不允许带有#号的,所以要将#号去除那么就要使用history模式,history模式还有一个问题就是,做刷新操作,会出现404错误,那么就需要和后端人配合让他配置一下apache或是nginx的url重定向,重定向到你的首页路由上。
  2. history模式与hash模式区别
    在这里插入图片描述
  3. history模式使用

    const router = new VueRouter({

    1. routes,
    2. mode:"history"

    })

案例:

  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4. <meta charset="UTF-8">
  5. <meta name="viewport" content="width=device-width, initial-scale=1.0">
  6. <meta http-equiv="X-UA-Compatible" content="ie=edge">
  7. <title>Document</title>
  8. </head>
  9. <body>
  10. <div id="demodiv">
  11. <router-link to="/index">首页</router-link>
  12. <router-link to="/home">小组</router-link>
  13. <router-link to="/phone">手机</router-link>
  14. <router-link to="/user">我的</router-link>
  15. <router-view ></router-view>
  16. </div>
  17. <!-- 创建一级路由模板start -->
  18. <template id="tema">
  19. <div>
  20. <p @click="fun()">{
  21. {tematext}}</p>
  22. </div>
  23. </template>
  24. <template id="temb">
  25. <div>
  26. home
  27. </div>
  28. </template>
  29. <template id="temc">
  30. <div>
  31. phone
  32. </div>
  33. </template>
  34. <template id="temd">
  35. <div>
  36. user
  37. <toplink></toplink>
  38. <router-view></router-view>
  39. </div>
  40. </template>
  41. <!-- 创建一级路由模板end -->
  42. <!-- 创建二级路由模板start -->
  43. <template id="ertema">
  44. <div>
  45. 我是二级路由11111111
  46. </div>
  47. </template>
  48. <template id="ertemb">
  49. <div>
  50. 我是二级路由22222222
  51. </div>
  52. </template>
  53. <template id="ertemc">
  54. <div>
  55. 我是二级路由33333333
  56. </div>
  57. </template>
  58. <template id="ertemd">
  59. <div>
  60. 我是二级路由44444444
  61. </div>
  62. </template>
  63. <!-- 创建二级路由模板end -->
  64. <template id="toplinktem">
  65. <div>
  66. <router-link to="/user/ertema">ertema</router-link>
  67. <router-link to="/user/ertemb">ertemb</router-link>
  68. <router-link to="/user/ertemc">ertemc</router-link>
  69. <router-link to="/user/ertemd">ertemd</router-link>
  70. </div>
  71. </template>
  72. </body>
  73. </html>
  74. <script src="node_modules/vue/dist/vue.js"></script>
  75. <script src="node_modules/vue-router/dist/vue-router.js"></script>
  76. <script>
  77. //一级路由组件start
  78. var tema={
  79. template:"#tema",
  80. data(){
  81. return{
  82. tematext:"我是index中的变量数据",
  83. }
  84. },
  85. methods:{
  86. fun(){
  87. alert("我是index的函数");
  88. }
  89. }
  90. };
  91. var temb={template:"#temb"};
  92. var temc={template:"#temc"};
  93. var temd={
  94. template:"#temd",
  95. components:{
  96. "toplink":{
  97. template:"#toplinktem"
  98. }
  99. }
  100. };
  101. //一级路由组件end
  102. // 二级路由组件start
  103. var ertema={template:"#ertema"};
  104. var ertemb={template:"#ertemb"};
  105. var ertemc={template:"#ertemc"};
  106. var ertemd={template:"#ertemd"};
  107. // 二级路由组件end
  108. //添加一级路由规则start
  109. var routes=[
  110. {name:"index",path:"/index",component:tema},
  111. {name:"home",path:"/home",component:temb},
  112. {name:"phone",path:"/phone",component:temc},
  113. {name:"user",path:"/user",component:temd,children:[
  114. {name:"ertema",path:"ertema",component:ertema},
  115. {name:"ertemb",path:"ertemb",component:ertemb},
  116. {name:"ertemc",path:"ertemc",component:ertemc},
  117. {name:"ertemd",path:"ertemd",component:ertemd}
  118. ]},
  119. {path:"/*",redirect:"/index"}
  120. ]
  121. //添加一级路由规则end
  122. // 创建路由实例
  123. const router = new VueRouter({
  124. routes,
  125. mode:"history"
  126. })
  127. new Vue({
  128. el:"#demodiv",
  129. data:{},
  130. router
  131. })
  132. </script>

2. 路由守卫/导航守卫

1. 全局前置守卫

  1. 当一个导航触发时,全局前置守卫(在进入组件之前)按照创建顺序调用。
  2. vue-router 提供的 router.beforeEach((to,from,next)=>{})可以方便地实现全局前置导航守卫
  3. to:即将要进入的目标 路由对象
  4. from: 当前导航正要离开的路由
  5. next: 下一步执行
    案例:

    // 创建路由实例
    const router = new VueRouter({

    1. routes

    })

    // **
    // **
    // **
    // 全局前置守卫
    // **
    // **
    router.beforeEach((to, from, next) => {

    1. if(to.path=="/home"||to.path=="/phone"){
    2. alert("对不起,请登录后再访问");
    3. next("/user");
    4. }else{
    5. next()
    6. }

    })

2. 全局后置钩子

  1. 当一个导航触发时,全局后置钩子(在进入组件之后)调用。
  2. vue-router 提供的 router.afterEach((to, from) => {})实现全局后置守卫
  3. to:即将要进入的目标 路由对象
  4. from: 当前导航正要离开的路由
    案例:

    // 创建路由实例
    const router = new VueRouter({

    1. routes

    })

    // **
    // **
    // 全局后置守卫
    // **
    // **
    router.afterEach((to,from)=>{

    1. console.log(from)

    })

案例:路由传参与路由卫士

  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4. <meta charset="UTF-8">
  5. <meta name="viewport" content="width=device-width, initial-scale=1.0">
  6. <meta http-equiv="X-UA-Compatible" content="ie=edge">
  7. <title>Document</title>
  8. </head>
  9. <body>
  10. <!-- 总流程:
  11. 1.下载需要的库文件
  12. 2.新建vue基本框架
  13. 3.根据当前这个功能新建1级路由
  14. 3-1。新建路由组件与组件模板的引用
  15. 3-2 新建路由规则
  16. 3-3 实例化路由对像===》传入路由规则
  17. 3-4 把路由对象传入 vue实例
  18. 3-5 在合适的位置传入 router-view 路由出口
  19. 必须要测试
  20. 4. 因为根据当前需要完成点击列表内容 跳转到详情页面 (数据如何在两个页面中传递)====》路由传参
  21. 思考?用params 的方式还是query的方式 一定要在笔记中再次查看两者的语法
  22. 在这个demo中我们使用params方式
  23. 4-1 设置路由规则的数据名
  24. 4-2 开始发送
  25. 4-3 接收并且测试本次路由传参是否正确的得到了数据
  26. 5. 开始设置数据(数据是通过ajax发送给后台并且返回)没有后台我们就用模拟数据
  27. 总流程完 -->
  28. <div id="demodiv">
  29. <topnav :obj="arr"></topnav>
  30. <router-view></router-view>
  31. </div>
  32. <!-- 创建一级路由模板start -->
  33. <template id="tema">
  34. <div>
  35. 首页
  36. </div>
  37. </template>
  38. <template id="temb">
  39. <div>
  40. <!-- 5-2便利新闻数据生成新闻列表的内容 -->
  41. <div v-for="(v,i) in listall">
  42. <!-- 4-2通过点击router-link 来进行路由传参的数据发送 -->
  43. <router-link :to="{name:'details',params:{id:v.id}}">
  44. <h1>{
  45. {v.title}}</h1>
  46. </router-link>
  47. </div>
  48. </div>
  49. </template>
  50. <template id="temc">
  51. <div>
  52. 详情
  53. <!-- 4-3在指定的魔板中进行路由传参的数据测试 -->
  54. {
  55. {this.$route.params.id}}
  56. <h1>{
  57. {text[0].title}}</h1>
  58. <p>{
  59. {text[0].con}}</p>
  60. </div>
  61. </template>
  62. <template id="temd">
  63. <div>
  64. 登录
  65. </div>
  66. </template>
  67. <!-- 创建一级路由模板end -->
  68. <template id="topnavtem">
  69. <div>
  70. <span v-for="(v, i) in obj">
  71. <router-link :to="v.linkurl">{
  72. {v.title}}</router-link>
  73. </span>
  74. </div>
  75. </template>
  76. </body>
  77. </html>
  78. <script src="node_modules/vue/dist/vue.js"></script>
  79. <script src="node_modules/vue-router/dist/vue-router.js"></script>
  80. <script>
  81. //创建一级路由组件start
  82. const tema={template:"#tema"};
  83. const temb={
  84. template:"#temb",
  85. data(){
  86. return {
  87. // 5.1设置详情数据
  88. listall:[
  89. {id:1,title:"路由传参和路由卫士",con:"本文链接:https://blog.csdn.net/qq_39200185/article/details/100126580"},
  90. {id:2,title:"逆向传值与路由",con:"本文链接:https://blog.csdn.net/qq_39200185/article/details/100109285"},
  91. {id:3,title:"Vue组件",con:"本文链接:https://blog.csdn.net/qq_39200185/article/details/100046528"},
  92. {id:4,title:"交互与实例的生命周期",con:"本文链接:https://blog.csdn.net/qq_39200185/article/details/100025112"}
  93. ]
  94. }
  95. }
  96. };
  97. const temc={
  98. template:"#temc",
  99. data(){
  100. return {
  101. // 5.1设置详情数据
  102. listall:[
  103. {id:1,title:"路由传参和路由卫士",con:"本文链接:https://blog.csdn.net/qq_39200185/article/details/100126580"},
  104. {id:2,title:"逆向传值与路由",con:"本文链接:https://blog.csdn.net/qq_39200185/article/details/100109285"},
  105. {id:3,title:"Vue组件",con:"本文链接:https://blog.csdn.net/qq_39200185/article/details/100046528"},
  106. {id:4,title:"交互与实例的生命周期",con:"本文链接:https://blog.csdn.net/qq_39200185/article/details/100025112"}
  107. ],
  108. text:[]
  109. }
  110. },
  111. // 新闻列表点击之后会给详情页面发送一个id 详情页面根据这个id找出对应的数据展示在页面中
  112. created(){
  113. // 5-3因为新闻列表页面跳转到当前新闻详情页面的时候 会把id传递过来
  114. console.log(this.$route.params.id);
  115. // 当前的数据.filter进行过滤
  116. this.text= this.listall.filter((v,i)=>{
  117. // 判断 路由传参传递过来的数据 如果等于 数据中原油的内容
  118. if(v.id==this.$route.params.id){
  119. // 取出相关的内容 并且返回给提前准备好的变量 在页面中展示
  120. return this.listall[i]
  121. }
  122. })
  123. }
  124. };
  125. const temd={template:"#temd"};
  126. //创建一级路由组件end
  127. const routes=[
  128. {name:"index",path:"/index",component:tema},
  129. {name:"list",path:"/list",component:temb},
  130. // 4-1 设置路由传参的数据名
  131. {name:"details",path:"/details/:id",component:temc},
  132. {name:"login",path:"/login",component:temd},
  133. ]
  134. const router = new VueRouter({
  135. routes
  136. })
  137. router.beforeEach((to,from,next)=>{
  138. if(to.path=="/index"){
  139. alert("您没有登录");
  140. next("/login")
  141. }else{
  142. next()
  143. }
  144. })
  145. new Vue({
  146. el:"#demodiv",
  147. router,
  148. data:{
  149. arr:[
  150. {linkurl:"/index",title:"首页"},
  151. {linkurl:"/list",title:"列表"},
  152. {linkurl:"/details",title:"详情"},
  153. {linkurl:"/login",title:"登录"}
  154. ]
  155. },
  156. components:{
  157. "topnav":{
  158. template:"#topnavtem",
  159. // 5-3详见props obj
  160. props:{
  161. obj:{
  162. type:Array,
  163. required:true
  164. }
  165. }
  166. }
  167. }
  168. })
  169. </script>

发表评论

表情:
评论列表 (有 0 条评论,614人围观)

还没有评论,来说两句吧...

相关阅读

    相关 VueRouter

    1. 前言 本小节我们介绍 VueRouter 路由组件传参。包括 params 传参、query 传参的两种方式。路由传参的知识点非常重要,在日常开发中,我们经常会通过

    相关 vue-03--

    和平时的页面跳转一样,我们可能需要在地址栏上传递某些参数,例如,从商品列表页面,跳转的某个商品的详情页面,这个时候,如果是页面跳转的时候,我们会直接在url上跟上一个商品id,

    相关 Vue跳转+

    之前在原生JS的开发中,我们经常会用到根据某一状态进行页面的跳转。 比如:登录成功跳到首页,点击商品列表的某个商品跳转商品详情等。 而常见的写法就是: locat