首页 > 解决方案 > Vuejs没有将属性传递给mounted

问题描述

有以下代码:

export default new Router({
  routes: [
    {
      path: '/noticia/:id',
      name: 'Noticia',
      component: Noticia,
      props: true
    }
  ]
})

export default {
  name: 'Noticia',
  data () {
    return {}
  },
  props: ['id'],
  computed: {
    noticia () {
      return this.$store.getters.noticia
    }
  },
  mounted: function () {
    this.$nextTick(function () {
      console.log(id)
      // Code that will run only after the
      // entire view has been rendered
    })
  }
}
<div>{{id}}</div>

问题是 {{id}} 由 html div 显示,但它没有传递给“mounted”,因此,我无法运行我的“console.log(id)”(因为它将运行代码来带来数据和将其放入计算中)。

我有其他代码运行相同的数据,运行轮,无法理解错误

标签: htmlvue.jsvue-routercomputed-properties

解决方案


mounted() {
   console.log( this.id )
}

推荐阅读