【问题标题】:Vuejs not passing property to mountedVuejs没有将属性传递给mounted
【发布时间】:2018-11-26 10:22:05
【问题描述】:

有如下代码:

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)'(因为它会运行代码带入数据并放入计算中)。

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

【问题讨论】:

  • 试试data () { return {id: null} }
  • 在mounted()中你应该使用:this.id
  • 使用 this.id

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


【解决方案1】:
mounted() {
   console.log( this.id )
}

【讨论】:

    【解决方案2】:

    为了让它在mounted上工作,刚刚做了:

    this.id 而不仅仅是 id

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2021-04-15
      • 1970-01-01
      • 1970-01-01
      • 2016-05-16
      • 1970-01-01
      • 2017-10-17
      • 2021-01-16
      • 1970-01-01
      相关资源
      最近更新 更多