useArticleHook.ts 970 B

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. import type {EsArticle} from "@/types";
  2. import {ref} from "vue";
  3. import Taro, {useLoad} from "@tarojs/taro";
  4. import {getArticleById} from "@/api/article";
  5. export default function useArticleHook() {
  6. //文章详情
  7. const article = ref<EsArticle>({
  8. article_name: '',
  9. category_id: 0,
  10. content: '',
  11. });
  12. //加载文章详情
  13. const loadArticle = async (id: number) => {
  14. const res = await getArticleById(id);
  15. article.value = res.data;
  16. article.value.content = article.value.content.replace(/&nbsp;/g, "")
  17. Taro.setNavigationBarTitle({
  18. title: article.value.article_name
  19. })
  20. }
  21. //页面显示生命周期
  22. useLoad(async (option) => {
  23. if (option) {
  24. console.log(option)
  25. }
  26. if (option?.id) {
  27. loadArticle(option.id as number)
  28. // loadGoodsSku(option?.goods_id)
  29. }
  30. })
  31. return {
  32. article,
  33. };
  34. }