30
src/store/modules/equipmentList.ts
Normal file
30
src/store/modules/equipmentList.ts
Normal file
@@ -0,0 +1,30 @@
|
||||
import { defineStore } from 'pinia';
|
||||
import { ref, computed } from 'vue';
|
||||
import { getDevicetList } from '@/api/equipmentList/index';
|
||||
|
||||
export const useDeviceStore = defineStore('devices', () => {
|
||||
// --- State (状态) ---
|
||||
// 相当于 Vuex 中的 state,用 ref 或 reactive 定义
|
||||
const deviceList = ref();
|
||||
|
||||
// --- Getters (计算属性) ---
|
||||
// 相当于 Vuex 中的 getters,直接用 computed 定义
|
||||
|
||||
// --- Actions (动作) ---
|
||||
// 相当于 Vuex 中的 actions/mutations,直接写同步或异步函数
|
||||
async function getdeviceList(query?: any) {
|
||||
try {
|
||||
const response = await getDevicetList(query);
|
||||
console.log('获取设备列表:', response);
|
||||
deviceList.value = response.data;
|
||||
} catch (error) {
|
||||
console.error('获取设备列表失败', error);
|
||||
}
|
||||
}
|
||||
|
||||
// ⚠️ 核心点:必须把需要暴露出去的变量和方法 return 出去!
|
||||
return {
|
||||
deviceList,
|
||||
getdeviceList
|
||||
};
|
||||
});
|
||||
Reference in New Issue
Block a user