如何观看$ attrs指令,特别是$ attr.value
您如何在VUE中观看$ attr.value
?
我有一个子组件:
<custom-component v-model="someData"/>
父组件中的某个地方:
this.$emit('input', this.dataToChild)
当我更新this.datatoChild
时,在父组件中,子组件中的V模型显示相应的更改。但是,我还希望对子组件中的yemedata
进行更改,以便在父组件中反映出this.datatoChild
将包含任何yemedata
>具有Somedata
更改时。我知道此更改反映到this。$ attr.value
。要注意更改,我知道我可以在VUE中使用观察者
。
我的问题是要观看的语法是什么。$ attr.value
?我知道要看一个我可以做的道具:
watch: {
propToWatch: function(newVal, oldVal) {
this.dataToChild = newVal
}
}
我也知道要观看一个我们可以的嵌套道具:
watch: {
'nested.propToWatch': function(newVal, oldVal) {
this.dataToChild = newVal
}
}
但是我不确定如何观看$ attr.value
,是否只是:
watch: {
'$attrs.val': function(newVal, oldVal) {
this.dataToChild = newVal
}
}
How do you watch $attrs.value
in vue?
I have a child component:
<custom-component v-model="someData"/>
Somewhere in the parent component:
this.$emit('input', this.dataToChild)
When I update this.dataToChild
in the parent component the v-model in the child component shows the corresponding changes. However I also want changes made to someData
in the child component to also reflect in the parent component, such that this.dataToChild
will contain whatever someData
has when someData
changes. I know this change is reflected to this.$attrs.value
. To watch for changes I know I can use watchers
in vue.
My question is what would be the syntax to watch this.$attrs.value
? I know to watch a prop I can just do:
watch: {
propToWatch: function(newVal, oldVal) {
this.dataToChild = newVal
}
}
I also know to watch a nested prop we can:
watch: {
'nested.propToWatch': function(newVal, oldVal) {
this.dataToChild = newVal
}
}
But I'm not sure how to watch $attrs.value
, would it just be:
watch: {
'$attrs.val': function(newVal, oldVal) {
this.dataToChild = newVal
}
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
![扫码二维码加入Web技术交流群](/public/img/jiaqun_03.jpg)
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
事实证明,就像您将如何使用嵌套道具(即:
Turns out it's just like how you would do it with a nested prop, ie: