Vue3| Pinia 的 action 异步写法

发布时间 2023-10-14 17:43:27作者: 嘎嘎鸭2
import { defineStore } from 'pinia'
import { ref } from 'vue'
import axios from 'axios'

export const useChannelStore = defineStore('channel', () => {
    const channelList = ref([])

    const getList = () => {
        axios({
            method: "get",
            url: "http://geek.itheima.net/v1_0/channels"
        }).then(resp => {
            channelList.value = resp.data.data.channels
            console.log(channelList.value)
        })
    }

    return {
        channelList,
        getList
    }
})