talk.ts 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. import { defineStore } from "pinia";
  2. import axios from "axios";
  3. import { nanoid } from "nanoid";
  4. import { reactive } from "vue";
  5. // export const useTalkStore = defineStore('talk1',{
  6. // state(){
  7. // return {
  8. // // list:[
  9. // // { id: "01", title: "今天你有点怪,哪里怪?怪好看的!" },
  10. // // { id: "02", title: "草莓、蓝莓、蔓越莓,今天想我了没?" },
  11. // // { id: "03", title: "心里给你留了一块地,我的死心塌地" },
  12. // // ]
  13. // list:JSON.parse(localStorage.getItem("talkList") as string) || []
  14. // }
  15. // },
  16. // actions:{
  17. // async getMain() {
  18. // let {data:{content:title}} = await axios.get("https://api.uomg.com/api/rand.qinghua?format=json");
  19. // console.log(title);
  20. // let obj = {
  21. // id:nanoid(),
  22. // title
  23. // }
  24. // this.list.push(obj);
  25. // // TalkStore.list.push(obj);
  26. // }
  27. // }
  28. // })
  29. export const useTalkStore = defineStore("talk1", () => {
  30. let list = JSON.parse(localStorage.getItem("talkList") as string) || [];
  31. async function getMain() {
  32. let {
  33. data: { content: title },
  34. } = await axios.get("https://api.uomg.com/api/rand.qinghua?format=json");
  35. console.log(title);
  36. let obj = {
  37. id: nanoid(),
  38. title,
  39. };
  40. list.push(obj);
  41. console.log(list,'最新')
  42. }
  43. return {
  44. list,
  45. getMain,
  46. };
  47. });