Closed BTMuli closed 1 year ago
环境:
相关代码:
// store/index.js import { createPinia } from 'pinia'; import { createUnistorage } from 'pinia-plugin-unistorage'; const store = new createPinia(); store.use( createUnistorage({ serializer: { serialize: JSON.stringify, deserialize: JSON.parse, }, }) ); export default store;
// main.js import { createSSRApp } from 'vue'; import App from '@/App.vue'; import store from '@/store'; export function createApp() { const app = createSSRApp(App); app.use(store); return { app, store, }; }
// store/modules/app.js import { defineStore } from 'pinia'; const useAppStore = defineStore({ id: 'app-store', state: () => ({ token: '', }), getters: {}, actions: { setToken(data) { this.token = data; } unistorage: true }); export default useAppStore;
执行安卓实机调试时终端报错
reportJSException >>>> exception function:createInstanceContext, exception:white screen cause create instanceContext failed,check js stack -> at useStore (app-service.js:5068:15) at (app-service.js:5192:22) at (app-service.js:10250:3)
进行 debug 后 console 显示信息:
尝试将 https://www.npmjs.com/package/pinia-plugin-unistorage 的 main.js 覆盖,仍旧报错
@BTMuli 你好,请使用 uniapp 独有的使用方式,具体可见 👉 使用
uniapp
经过测试发现采用 README 中的引用方式无法解决,该报错是因为在某页面使用 useStore() 位于 data() 之前导致的,将 useStore 放在 methods 内即可解决, 但其他小程序端跟H5端采用改写法并未出现问题。
useStore()
data()
useStore
methods
@BTMuli 文档有对应描述 👉 outside-component-usage
我懂了,这是因为安卓应用没有 SSR 渲染吗?
环境:
相关代码:
执行安卓实机调试时终端报错
进行 debug 后 console 显示信息:
尝试将 https://www.npmjs.com/package/pinia-plugin-unistorage 的 main.js 覆盖,仍旧报错