I'm relatively new to vue.js and especially nuxt. I have a small function to get data from the backend and update a table. I'm not sure how to debug this task as I'm calling this in a mounted hook and I can see the data in vuex tab when I load the page.
payload:Object
count:2
next:null
previous:null
results:Array[2]
0:Object
1:Object
created_at:"2020-09-14T12:00:00Z"
event_name:"wrw"
id:2
market_name:"wrwr"
market_type:"wrwr"
odds:242
runner_name:"wrwr"
side:"wrwrw"
stake:424
For some reason I cannot populate the table. I can see that the function pollData() Is being called every three seconds after page loads. I'm not sure why I can't see the data in the table.
How do I update a table with vuex data?
<template>
<div id="app">
<h1>Orders</h1>
<table>
<thead class="thead-dark">
<tr>
<th>Time Stamp</th>
<th>Event Name</th>
<th>Market Name</th>
<th>Market Type</th>
<th>Runner Name</th>
<th>Side</th>
<th>Odds</th>
<th>Stake</th>
</tr>
</thead>
<tbody>
<tr v-for="o in polling" :key="o.id">
<td>{{o.created_at}}</td>
<td>{{o.event_name}}</td>
<td>{{o.market_name}}</td>
<td>{{o.market_type}}</td>
<td>{{o.runner_name}}</td>
<td>{{o.side}}</td>
<td>{{o.odds}}</td>
<td>{{o.stake}}</td>
</tr>
</tbody>
</table>
</div>
</template>
<script>
import axios from "axios";
import { mapMutations } from 'vuex'
export default {
data () {
return {
polling: null
}
},
methods: {
pollData () {
this.polling = setInterval(() => {
this.$store.dispatch('getOrders')
}, 3000)
}
},
beforeDestroy () {
clearInterval(this.polling)
},
mounted () {
this.pollData()
}
}
</script>
polling, but that's set to the timer ID (an integer) inpollData().getOrdersfetches data, store the result in a Vuex state variable, then update yourv-forto iterate that state variable.