资讯

精准传达 • 有效沟通

从品牌网站建设到网络营销策划,从策略到执行的一站式服务

vue子路由参数怎么传递与接收

这篇文章主要介绍“vue子路由参数怎么传递与接收”,在日常操作中,相信很多人在vue子路由参数怎么传递与接收问题上存在疑惑,小编查阅了各式资料,整理出简单好用的操作方法,希望对大家解答”vue子路由参数怎么传递与接收”的疑惑有所帮助!接下来,请跟着小编一起来学习吧!

专注于为中小企业提供成都网站设计、网站制作、外贸营销网站建设服务,电脑端+手机端+微信端的三站合一,更高效的管理,为中小企业涵江免费做网站提供优质的服务。我们立足成都,凝聚了一批互联网行业人才,有力地推动了上千多家企业的稳健成长,帮助中小企业通过网站建设实现规模扩充和转变。

2.main.js中修改

import Vue from 'vue'
// import Router from './Router'     /*引用自同级Router.js*/
import Router from './SonRouter'     /*引用自同级SonRouter.js*/

vue子路由参数怎么传递与接收

3.src下新建文件SonRouter.js

/*子路由*/
import Vue from 'vue'
import VueRouter from 'vue-router'
Vue.use(VueRouter)
//声明模版,点击链接显示对应的内容
const first = { template:'
first内容
'} const second = { template:'
second内容
'} const Home = { template:'
Home内容
'} const firstFirst = { template:'
firstFirst内容 {{$route.params.id}} {{$route.params.name}}
'} const firstSecond = { template:'
firstSecond内容 {{$route.params.id}} {{$route.params.name}}
'} //单独的写组件模版的时候可直接这样写,名称自定义 const sonRunterTemplate ={   template:`                    

组件

                     
  ` } //router自己定义名字 const router = new VueRouter({   mode:'history',   base:__dirname, //当前的路径   dirname在node中指当前的本地路径   routes:[       //以数组的方式给出  [{},{}],多个的话一定是routes复数形式     {path:'/',name:'Home',component:Home},     {path:'/first',component:sonRunterTemplate,         children:[           {path:'/',name:'Home-First',component:first},           {path:'first',name:'Home-First-First',component:firstFirst},           {path:'second',name:'Home-First-Second',component:firstSecond}         ]     },     {path:'/second',name:'Home-Second',component:second}   ] }) new Vue({   router,   template:`              

导航

        

{{$route.name}}

         
                
  1. /
  2.                 
  3. first
  4.                 
                          
    1. first
    2.                     
    3. second
    4.                 
                
  5. second
  6.           
                  
    ` }).$mount('#app') /* 路由中参数的传递:     1.通过路由传参 name:'Home-First'   获取 

{{$route.name}}

    2.绑定to方式进行参数的传递  :to="{name:'Home-First-Second',params:{id:258,name:'李四'}}"  获取{{$route.params.id}} {{$route.params.name}}     */ /* route 路线  $route.params router  路由 routes  路由复数形式  一定是数组 */

运行结果:
vue子路由参数怎么传递与接收

到此,关于“vue子路由参数怎么传递与接收”的学习就结束了,希望能够解决大家的疑惑。理论与实践的搭配能更好的帮助大家学习,快去试试吧!若想继续学习更多相关知识,请继续关注创新互联网站,小编会继续努力为大家带来更多实用的文章!


名称栏目:vue子路由参数怎么传递与接收
标题URL:http://cdkjz.cn/article/gehess.html
返回首页 了解更多建站资讯
多年建站经验

多一份参考,总有益处

联系快上网,免费获得专属《策划方案》及报价

咨询相关问题或预约面谈,可以通过以下方式与我们联系

业务热线:400-028-6601 / 大客户专线   成都:13518219792   座机:028-86922220