You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
canteen/inventoryStore.js

61 lines
1.4 KiB

import {
defineStore
} from 'pinia';
import req from "../request"
import {
ElMessage
} from 'element-plus'
export const useInventoryStore = defineStore('inventoryStore', {
state: () => ({
inventoryList: [],
}),
getters: {
inventoryListGetter() {
return this.inventoryList
}
},
actions: {
getInventoryList() {
req({
method: "get",
url: "/inventory",
}).then(({
data
}) => {
if (data.code === 0) {
this.setInventoryList(data.data)
ElMessage({
message: "获取成功",
type: "success"
})
}
})
},
setInventoryList(data) {
this.inventoryList = data;
console.log(this.inventoryList, "inventoryStoreData")
},
updateInventoryList(data) {
req({
method: "put",
url: "/inventory",
data,
}).then(({
data
}) => {
if (data.code === 0) {
this.setInventoryList(data.data, "changedInventory")
ElMessage({
message: "修改成功",
type: "success"
})
}
})
},
}
});