index.js
1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
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
}