• get请求
import {reqCategoryList} from '@/api'

const state = {
  categoryList:[]
}
const mutations = {
  RECEIVE_CATEGORYLIST(state,categoryList){
    state.categoryList = categoryList
  }
}
const actions = {
  async getCategoryList({commit}){
    const result = await reqCategoryList()
    if(result.code === 200){
      commit('RECEIVE_CATEGORYLIST',result.data)
    }
  },
}


const getters = {

}

export default {
  state,
  mutations,
  actions,
  getters
}
  • post请求
import { reqGoodsListInfo } from "@/api"
const state = {
  goodsListInfo:{}
}
const mutations = {
  RECEIVE_GOODSLISTINFO(state,goodsListInfo){
    state.goodsListInfo = goodsListInfo
  }
}
const actions = {
  async getGoodsListInfo({commit},searchParams){
    const result = await reqGoodsListInfo(searchParams)
    if(result.code === 200){
      commit('RECEIVE_GOODSLISTINFO',result.data)
    }
  }
}
const getters = {
  goodsList(state){
    return state.goodsListInfo.goodsList || []
  }
}

export default {
  state,
  mutations,
  actions,
  getters
}
posted on 2021-07-23 19:38  文种玉  阅读(59)  评论(0编辑  收藏  举报