Files
2024-06-24 16:46:59 +07:00

46 lines
1.3 KiB
TypeScript

interface ArticleCondition {
ids?: number[]
}
export const useArticleStore = defineStore("article", () => {
const currentArticle = ref<any>({});
const currentArticles = ref<any[]>([])
const getArticleById = async (id: string | number) => {
try {
const { data } = await useFetch(`/api/articles/get-by-id/${id}`)
currentArticle.value = {}
currentArticle.value = data.value.item
} catch (error: any) { }
}
const getArticleBySlug = async (slug: string) => {
try {
const article = await $fetch(`/api/articles/get-by-slug/${slug}`)
currentArticle.value = {}
currentArticle.value = article?.item
return currentArticle;
} catch (error: any) { }
}
const getArticleCondition = async (condition: ArticleCondition) => {
try {
const { data: articles } = await useFetch(`/api/articles/condition`, {
method: 'POST',
body: condition
})
} catch (error: any) {
}
}
return {
currentArticle,
getArticleById,
getArticleBySlug,
getArticleCondition
}
});
import.meta.hot && import.meta.hot.accept(acceptHMRUpdate(useArticleStore, import.meta.hot));