【发布时间】: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