admin管理员组文章数量:1327689
Is there any way to get puted data from child ponent to parent ponent? Because I'm sending the data from parent to child first and then I want to use the uted property (data) in the parent ponent. I want to do that because I want to reuse that important ponent (child) in other ponents too.
I have a search input field for filtering my items, and when i wrote something down i wanna get back that list from the child ponent.
Parent ponent
<input class="form-control form-control-search m-input" autoplete="off" type="text" v-on:input='testFunc()' v-model="search" placeholder="Search...">
<paginate-links v-if="items.length > 0" :models="items">
<div class="m-list-timeline__item no-timeline" v-for="item in filterItems" v-bind:key="item.id">
{{ item.title }}
</div>
</paginate-links>
Child ponent
props: ['item']
puted: {
filterItems () {
return filter // here goes my code
}
}
So can i get the filterItems
in the parent ponent?
Is there any way to get puted data from child ponent to parent ponent? Because I'm sending the data from parent to child first and then I want to use the uted property (data) in the parent ponent. I want to do that because I want to reuse that important ponent (child) in other ponents too.
I have a search input field for filtering my items, and when i wrote something down i wanna get back that list from the child ponent.
Parent ponent
<input class="form-control form-control-search m-input" autoplete="off" type="text" v-on:input='testFunc()' v-model="search" placeholder="Search...">
<paginate-links v-if="items.length > 0" :models="items">
<div class="m-list-timeline__item no-timeline" v-for="item in filterItems" v-bind:key="item.id">
{{ item.title }}
</div>
</paginate-links>
Child ponent
props: ['item']
puted: {
filterItems () {
return filter // here goes my code
}
}
So can i get the filterItems
in the parent ponent?
- Sending Messages To Parents With Events – Daniel Beck Commented May 18, 2018 at 14:30
- 3 Possible duplicate of Update parent model from child ponent Vue – Daniel Beck Commented May 18, 2018 at 14:33
-
Can you clarify
uted property (data)
? they're not the same. puted property is a reactive cached value that you can utilise a hook on, with data, you usewatch
to add hooks – Daniel Commented May 18, 2018 at 14:48 - Sorry i meant just puted property. Because im getting something back with it right? Thats why I wrote data. – user6218868 Commented May 18, 2018 at 21:20
1 Answer
Reset to default 7There are a couple ways you can send data back to the parent, but probably the easiest way I'd say is using an emit within the puted.
in child:
puted:{
myVal() {
let temp = this.num + 1;
this.$emit('onNumChange', temp);
return temp;
}
}
in parent template:
<my-child-ponent @onNumChange="changeHandler"/>
in parent script
methods: {
changeHandler(value) {
console.log('Value changed to: ', value);
}
}
You could do a similar thing with watch
, or pass a function from parent as a prop that notifies the parent, but my remended way would be to use vuex
https://vuex.vuejs/en/
本文标签: javascriptCan I get computed data from child component to parent componentStack Overflow
版权声明:本文标题:javascript - Can I get computed data from child component to parent component? - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1742218245a2434964.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论