• This project
    • Loading...
  • Sign in

Bad / exercising · Files

Go to a project

GitLab

  • Go to dashboard
  • Project
  • Activity
  • Files
  • Commits
  • Pipelines 0
  • Builds 0
  • Graphs
  • Milestones
  • Issues 0
  • Merge Requests 0
  • Members
  • Labels
  • Wiki
  • Forks
  • Network
  • Create a new issue
  • exercising
  • sheep
  • store
  • global.js
  • 初始化
    2dbc8307
    by Bad
    2026-06-11 16:07:52 +0800  
    Browse Files
global.js 450 Bytes
Raw Blame History Permalink
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24
import { defineStore } from 'pinia'

// 全局变量 Store
export const useGlobalStore = defineStore('global', {
  state: () => ({
    // 
    myGlobalVar: '我是全局变量',
    token: '',
    isLogin: false,
  }),
  
  // 修改全局变量的方法
  actions: {
    setMyGlobalVar(val) {
      this.myGlobalVar = val
    },
    setToken(val) {
      this.token = val
    },
  },

  // 持久化(关闭小程序不丢失)
  persist: true,
})