I'm loading two components on a page on my Django project, one is used to query some data from my backend and another is used to load some forms.
Since the form component is loaded four times on the page (with different parameters) i can't query data from that component because i would make four queries (one for each component) while i only need to do one, so i decided to use one component to make the query, while the form component should only receive the data and show it on the page along with the form.
So i have this function in get_data.vue
:
..
methods: {
fetchBalance() {
fetch('MY-BACKEND')
.then(response => response.json())
.then(data => {
var freeBalance = data['freeBalance']
var totalBalance = data['totalBalance']
})
},
}
..
And then i have form.vue
<template>
...
</template>
<script>
export default {
props:{
order:{
type:String,
default:'amount'
},
side:{
type:String,
default:'price'
},
},
mounted() {
},
data() {
return {
name: '',
description: '',
output: ''
};
},
methods: {
formSubmit() {
let currentObj = this;
axios.post('MY-BACKEND', {
price: this.price,
amount: this.amount,
}
.then(function (response) {
currentObj.output = response.data;
}
.catch(function (error) {
currentObj.output = error;
});
},
}
}
</script>
Somehow, i need to access the variablesfreeBalance
and totalBalance
in get_data.vue
from form.vue
. How can i do this? I was thinking of using Vuex, but i wanted to see if there was another way to do it without using Vuex, since it might be a bit overkill for this task.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…