本文主要是介绍uniapp微信小程序开发踩坑日记:Pinia持久化报错Cannot read property ‘localStorage‘ of undefined,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
插件默认使用 localStorage
实现持久化,小程序端不兼容,需要替换持久化 API
import { defineStore } from 'pinia'
export const useCommonStore = defineStore('pack-store', {state: (): State => ({wwInfo: {},globalData: {},timerLock: false, //是否关闭合成定时器}),getters: {},actions: {setWwInfo: (state: State, data: any) => {this.wwInfo = data;//注意这里不用加state。直接this就行}, },{// 配置持久化persist: {// 调整为兼容多端的APIstorage: {setItem(key, value) {uni.setStorageSync(key, value) },getItem(key) {return uni.getStorageSync(key) },},}, }, )
这篇关于uniapp微信小程序开发踩坑日记:Pinia持久化报错Cannot read property ‘localStorage‘ of undefined的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!