ITPub博客

首页 > IT职业 > IT生活 > vue params 链接传值

vue params 链接传值

IT生活 作者:lihui48 时间:2021-09-09 10:37:46 0 删除 编辑

HelloWord.vue

<template>
  <div class="hello">
    <h1>{{msg}}</h1>
    <router-link :to="{ name:'children', params: {id: 222,cid:333} }">
      显示
    </router-link>
  </div>
</template>

children.vue

<template>
    <div>{{ id }}--{{ cid }}</div>
</template>
<script>
export default {
    name:'children',
    data(){
        return{
            id:'',
            cid:''
        }
    },
    created(){
        this.id = this.$route.params.id,
        this.cid = this.$route.params.cid
    }
}
</script>
<style scoped>

</style>

router.vue

import Vue from 'vue'
import Router from 'vue-router'
import HelloWorld from '@/components/HelloWorld'
import children from '@/components/children'

Vue.use(Router)

export default new Router({
  routes: [
    {
      path: '/',
      name: 'HelloWorld',
      component: HelloWorld
    },
    {
      path:'/detail/:id',
      name:'children',
      component:children
    }
  ]
})

记录一下!

来自 “ ITPUB博客 ” ,链接:https://blog.itpub.net/1469/viewspace-2824332/ ,如需转载,请注明出处,否则将追究法律责任。

请登录后发表评论 登录
全部评论

注册时间:2019-04-15

  • 博文量
    108
  • 访问量
    689