index.js 1 KB
import {shopGoods,goods,exchange} from "@/api/shop/index.js"

const state = {
	// 商城数据
	shopGoods:[],
	// 商城对应物品
	goods:[]
};
const mutations = {
	//存储商城物品
	GAINSHOPGOODS(state,data){
		state.shopGoods = data
	},
	// 存储商城对应物品
	GAINGOODS(state,data){
		state.goods = data
	}
};
const actions = {
	//获取商城物品
	async gainShopGoods({commit}){
		let result = await shopGoods()
		if (result.code == 200) {
		      commit("GAINSHOPGOODS", result.data)
		}
	},
	//获取商城内对应的物品
	async gainGoods({commit},numId){
		let result = await goods(numId)
		console.log(result);
		if (result.code == 200) {
		      commit("GAINGOODS", result.data)
		}
	},
	//兑换物品
	async gainExchange({commit},data){
		let result = await exchange(data)
		console.log(result);
	}
};
const getters = {
	// 商城对应物品
	NumIdGoods(){
		return state.goods
	}
}

export default {
    state,
    mutations,
    actions,
	getters
}