How to initialize the way that `state` uses the network request API?

how do I initialize state how to use the network to request API?

const store = new Vuex.Store({
  state: {
    todos: [
      { id: 1, text: "...", done: true },
      { id: 2, text: "...", done: false }
    ]
  },
  

I have a todos in state, I want to initialize it by requesting API. How do I write it here?

Mar.12,2021

import   {gettodos} from 'api'
state: {
    todos: []
  },
  mutations: {
    SET_TODOS: (state,todos) => {
      state.todos = todos
    }
  },
  actions: {
    getTodos({ commit }) {
      return new Promise(resolve => {
        gettodos(state.token).then(res => {
          commit('SET_TODOS', res.data.xxxx)
        }).catch(error => {
          reject(error)
        })
      })
    }
  }

in the place where you initialize this.$store.dispatch (getTodos, {parameter})
if the data is returned to the page, you directly want to add resolve (res.data)

.
MySQL Query : SELECT * FROM `codeshelper`.`v9_news` WHERE status=99 AND catid='6' ORDER BY rand() LIMIT 5
MySQL Error : Disk full (/tmp/#sql-temptable-64f5-1bf2164-31612.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
MySQL Errno : 1021
Message : Disk full (/tmp/#sql-temptable-64f5-1bf2164-31612.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
Need Help?