0๐
You can emit an event and let the parent component handle the fetching and pass the data as props to the child component.
Or another way is to directly listen to the event as follows
Component 1:
this.$root.$emit('clickPrices', data);
Component 2:
mounted() {
this.$root.$on('clickPrices', data => {
this.getPricing();
});
}
Check out the answer by @alex
- [Vuejs]-How to not get some data based on records in another table with laravel eloquent?
- [Vuejs]-Is there any way to mount function in sidedrawer?
0๐
Since you are using 2 independent components (one is not included in the other), you cannot pass props
Things you can do โ
-
Instead of fetching all the prices on click, just create a created hook like so, which will fetch all the pricing details whenever your component is created โ
created () { this.getPricing() }, methods: { getPricing() { axios.get('api/pricing').then((response) => { //some actions router.push('prices'); }); }, },
-
Use State and when a user clicks on the button, pricing details are fetched and added in the state. And you can just use the state anywhere in your application like so โ
this.$store.state.prices
Let me know if it works, if not we will find some other solution for you!
- [Vuejs]-Vue components re-rendering on router push
- [Vuejs]-How to clear error when writing EJS in html