import { defineStore } from 'pinia';export const userInfo = defineStore('userInfo', {state: () => {return {userToken: uni.getStorageSync('token') || '',};},actions: {// 添加tokenupdateToken(token: string) {uni.setStorageSync('token', token);this.userToken = token}}
});
使用
import {userInfo} from '@/stores/userInfo'import {ref} from "vue";const test = userInfo()const tst = ref('4')test.updateToken(tst.value)
效果