3π
β
Blockquote
You can use life-cycle hook mounted
to fetch data on initial page load.
export default {
data() {
return {
balances: [],
}
},
mounted() {
this.fetchData()
},
methods: {
fetchData() {
fetch('http://127.0.0.1:8000/binance/getbalance')
.then(response => response.json())
.then(data => {
this.balances = data
})
}
}
}
you can also use created
to fetch data on initial page created is executed before mounted for reference enter link description here e.g.
export default {
data() {
return {
balances: [],
}
},
created() {
this.fetchData()
},
methods: {
fetchData() {
fetch('http://127.0.0.1:8000/binance/getbalance')
.then(response => response.json())
.then(data => {
this.balances = data
})
}
}
}
π€Nilesh Patel
0π
You are doing it wrong, youβre not using vue correctly:
<script>
export default {
created() {
fetch('http://127.0.0.1:8000/binance/getbalance')
.then(response => response.json())
.then(data => {
this.balances = data
})
},
data () {
return {
balances: [],
}
},
}
</script>
π€Tomer
Source:stackexchange.com