vue 技巧 props获取动态路由 路由去掉#/ wacth深度 路由传参

动态路由的值获取

可在动态路由对象里面再加一个属性,props:true。用于将动态值传到,相应使用的组件上。相应组件用props接收。
props的几种写法:

  • 数组型:props: [‘title’, ‘likes’, ‘isPublished’, ‘commentIds’, ‘author’]
  • 对象类型:props:{
    title: String,
    likes: Number,
    isPublished: Boolean,
    commentIds: Array,
    author: Object,
    callback: Function,
    contactsPromise: Promise // or any other constructor
    }
  • props文档:https://cn.vuejs.org/v2/guide/components-props.html

路由的定向与去掉#

  • 去掉#:
export default new Router({
  "mode":"history"
  })
  • 定向用:redirect
export default new Router({
   routes:[{
     path:'/'
     redirect:'/join'// 这里就是首页展示的文件
   }]
 })

wacth 监听

    watch: {
    firstName: {
      handler(newName, oldName) {
        this.fullName = newName + ' ' + this.lastName;
      },
      // 代表在wacth里声明了firstName这个方法之后立即先去执行handler方法
      immediate: true,
      deep:true // 深度监听
    }
  }

router

  • http://localhost:8080/#/index?name=1
    
   //  参数传递
  <router-link :to="{path:'/index',query: {name: id}}">
  // 接收参数
  this.$route.query.id
  • 传参
https://router.vuejs.org/zh/guide/essentials/passing-props.html#%E5%B8%83%E5%B0%94%E6%A8%A1%E5%BC%8F
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值