Vuejs没有将属性传递给挂载

时间:2018-06-17 07:59:40

标签: html vue.js vue-router computed-properties

拥有以下代码:



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>
&#13;
&#13;
&#13;

问题是{{id}}由html div显示,但它没有传递给&#39;已安装&#39;,因此,我无法运行我的&#39; console.log(id )&#39; (因为它会运行一个代码来传输数据并将其放入计算中)。

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

2 个答案:

答案 0 :(得分:1)

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

答案 1 :(得分:0)

要让它在挂载时工作,只需执行:

this.id而不仅仅是id