亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

Vue JS-無法使用來自 Vuex 的數據更新 html 表

Vue JS-無法使用來自 Vuex 的數據更新 html 表

30秒到達戰場 2023-04-27 16:18:54
我對 vue.js 比較陌生,尤其是 nuxt。我有一個小功能可以從后端獲取數據并更新表格。我不確定如何調試這個任務,因為我在掛載的鉤子中調用它,當我加載頁面時,我可以在 vuex 選項卡中看到數據。payload:Objectcount:2next:nullprevious:nullresults:Array[2]0:Object1:Objectcreated_at:"2020-09-14T12:00:00Z"event_name:"wrw"id:2market_name:"wrwr"market_type:"wrwr"odds:242 runner_name:"wrwr"side:"wrwrw"stake:424由于某種原因,我無法填充表格。 我可以看到頁面加載后每三秒調用一次函數pollData() 。我不確定為什么我看不到表中的數據。如何使用 vuex 數據更新表?    <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>
查看完整描述

1 回答

?
婷婷同學_

TA貢獻1844條經驗 獲得超8個贊

您沒有從您的商店獲取投票數據。


<script>

import { mapState } from "vuex";

export default {

  

  // remove polling from data object and

  

  computed: {

    ...mapState({

      polling: (state) => state.polling.polling, // Give the correct path.

    })

  },

  created() {

    this.pollData();

  }

}

</script>

如果我是你,我會在創建的鉤子中調用 this.pollData() 。


查看完整回答
反對 回復 2023-04-27
  • 1 回答
  • 0 關注
  • 128 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號