1👍
One simple way to do this is to have the parent handle the communication with some events.
In the parent:
<app-filter @applied="filtersApplied"></app-filter>
and
methods: {
filtersApplied (filters) {
this.keyword = filters.keyword
this.time = filters.time
}
}
And in the AppFilter component:
submit () {
this.$emit('applied', { keyword: this.keyword, time: this.time })
}
EDIT
I noticed you’re talking about how you’re doing the call in created(). There’s a couple solutions to that as well.
- You can use sub-component/nested routing, so on submit you add them as query parameters to the URL which will cause the component to re-load and created() will be called again. Check out nested routing in the Router api here
- You can use watchers. Since you want to know if either changes, you’ll probably want to watch a computed property which includes them both. In the AppRequest component put:
computed: { combined() { this.keywords && this.time} }
andwatch: { combined() { makeApiRequest() } }
- [Vuejs]-Object value is changed but component is not updated
- [Vuejs]-VUE | Javascript : How to access a key as a date format?
Source:stackexchange.com