footer-content-pages.ts 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  1. import { defineStore } from 'pinia'
  2. import axios from 'axios'
  3. export const useFooterLinksStore = defineStore('footerLinks',{
  4. state: () => ({
  5. token: "c1f8dac9ec1b803aa0902dced56958c91115acbbc216832757f95457d25bde1682863bb6144d574297560f3139f0e8610d05509a4d37ec19b96d0366f4b3ccdd246c97cdff0d877eb12ec3272b58d3203fd050267c5d089b68b9e8198534d74ded49564a6a5bd64e3825b617b0f0a6fe07fdada4ae941f15b6b144abdc89d804",
  6. locale: (localStorage.getItem('lang') || 'de'),
  7. links: []
  8. }),
  9. actions: {
  10. async getLinks(locale:string){
  11. await this.setLocale(locale)
  12. return this.links
  13. },
  14. getLinkByLabel(oldLabel:string){
  15. return this.links.find((link:any) => (link.Label as string) == oldLabel)
  16. },
  17. async setLocale(locale:string){
  18. if (this.links.length == 0 || this.locale != locale){
  19. this.locale = locale
  20. await this.fetchLinks()
  21. }
  22. },
  23. async fetchLinks(){
  24. const response = await axios.get('https://strapi.kornblum.one/api/footer-content-pages?&populate[localizations][fields][0]=Label&populate[page][fields][1]=path&locale='+this.locale, {
  25. headers: {
  26. Authorization: "Bearer "+this.token,
  27. },
  28. })
  29. this.links = response.data.data
  30. },
  31. }
  32. })