yn_img_tools_app/src/stores/modules/common.js

40 lines
1.0 KiB
JavaScript

import { ref } from 'vue'
import { defineStore } from 'pinia'
import { getProjectApi, getMajorApi } from '@/services/common'
export const useCommonStore = defineStore('common', () => {
// 项目数据
const projectList = ref([])
// 专业数据
const majorList = ref([])
// 存储项目数据
const getProjectList = async () => {
if (projectList.value.length < 1) {
const { data: result } = await getProjectApi({})
projectList.value = result
return projectList.value
} else {
return projectList.value
}
}
// 存储专业数据
const getMajorList = async () => {
if (majorList.value.length < 1) {
const { data: result } = await getMajorApi()
majorList.value = result
return majorList.value
} else {
return majorList.value
}
}
// 把数据和方法 return 出去
return {
projectList,
majorList,
getProjectList,
getMajorList,
}
})