【发布时间】:2021-08-07 22:40:04
【问题描述】:
我正在使用 props 将值从一个 vue.js 组件传递到另一个。我在我的“mounted()”函数中使用了这个 props 值。我在下面设置的警报正确显示了从道具接收到的“this.Id”变量的填充值。但是,之后在 axios 帖子中使用相同的变量时未定义。这怎么可能?
mounted () {
this.$nextTick(function () {
alert(this.Id)
axios.post('/api/title', this.Id)
.then((response) => {
...
})
})
}
谢谢。 J
【问题讨论】:
-
你为什么使用
this.$nextTick?这看起来不像你会使用它的地方。 -
$nextTick的回调应该是一个箭头函数。但我不明白你所描述的行为是如何可能的。你能分享一个复制的链接吗?
标签: javascript node.js vue.js