html - 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)”(因为它将运行代码来带来数据和将其放入计算中)。
我有其他代码运行相同的数据,运行轮,无法理解错误
解决方案
mounted() {
console.log( this.id )
}
推荐阅读
- regex - 如何避免使用正则表达式的 HTML 代码
- javascript - 我正在尝试为我的班级编写一个简单的密码验证系统,但它不起作用
- hyperparameters - 使用 Keras Tuner 对迁移学习模型进行超参数优化
- php - CSS图像的延迟加载
- c++ - 使用 getline 读取但用户需要使用两次回车
- elasticsearch - 我无法在与 elasticsearch 连接的 grafana 中选择字段
- sql - 计算数字的sql无法正常工作
- amazon-web-services - 在 AWS API Gateway 中使用请求正文作为缓存键
- html - 内容后面的 Css Navbar(z-index 不起作用)
- deployment - 无法启动服务 VisualStudioRemoteDeployer