vue params传值

handleEdit(index, row) {

   // let id = row._id
    this.$router.push({name: 'news-edit', params : {
      new : row
    }, query: {id: row._id, type: 'edit'}})
  },

让 let id = row._id ,显示id=undefined 但是row._id是有值得 不知道为啥

mounted() {

  debugger
  console.log(this.$route.query.type)
  if ( "edit" == this.$route.query.type ){
    let old = this.$route.params.new
    this.title = old.title
    this.author = old.author
    this.content = old.content
    this.abstract = old.abstract
    this.coverImage = old.coverImage
  }
  console.log(this.title)
},

old也是同样问题 导致下面的title啥的都获取不到

阅读 2.8k
1 个回答

params参数要在路由中声明。比如url是/newsedit,后面要穿一个叫new的params参数,那路由里要声明:

{
    path: '/newsedit/:new',
    component: xxx
}

不然的话你页面刷新后 这个new值就获取不到了。
query参数的话可以不声明。

撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题