[英]Change parent property from within emitted child component method in Vue js
Inside vue component I have another child component datatabel
which has emitted method sort
在
datatabel
组件内部,我有另一个子组件数据表,它发出了方法sort
<datatable @sort="sortBy"></datatable>
Currently the emitted sort
method calls another method sortBy
in parent component, which then updates a property in the parent.当前发出的
sort
方法调用父组件中的另一个方法sortBy
,然后更新父组件中的属性。
Is it possible to update the parent property directly form emitted sort
method?是否可以直接从发出的
sort
方法更新父属性?
Something like this:像这样的东西:
<datatable @sort="parentAttribute = 'value that was emitted'"></datatable>
The above example doesn't work, but I am not probably doing it right.上面的例子不起作用,但我可能做得不对。
Can that be done, if so, what would be the right syntax?可以这样做吗,如果可以,正确的语法是什么?
Yes you can access the event payload with $event
是的,您可以使用
$event
访问事件有效负载
<datatable @sort="parentAttribute = $event"/>
https://v2.vuejs.org/v2/guide/components-custom-events.html https://v2.vuejs.org/v2/guide/components-custom-events.html
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.