29 lines
894 B
TypeScript
29 lines
894 B
TypeScript
export const useArticleStore = defineStore("article", () => {
|
|
const currentArticle = 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 { data: article } = await useAsyncData('article', () => $fetch(`/api/articles/get-by-slug/${slug}`))
|
|
currentArticle.value = {}
|
|
currentArticle.value = article.value?.item
|
|
} catch (error: any) {}
|
|
}
|
|
|
|
return {
|
|
currentArticle,
|
|
getArticleById,
|
|
getArticleBySlug
|
|
}
|
|
});
|
|
|
|
import.meta.hot && import.meta.hot.accept(acceptHMRUpdate(useArticleStore, import.meta.hot));
|