m***@meenw.com
m***@meenw.com
  • 发布:2024-11-09 12:06
  • 更新:2024-11-13 21:02
  • 阅读:151

pinia使用运行就白屏报错

分类:uni-app

使用HBuilderX建的uniapp

真机运行报错信息:
reportJSException >>>> exception function:createInstanceContext, exception:white screen cause create instanceContext failed,check js stack ->
at useStore (app-service.js:1855:15)
at (app-service.js:2038:3)
at (app-service.js:2110:3)

main.js

import App from './App'  

// #ifndef VUE3  
import Vue from 'vue'  
import './uni.promisify.adaptor'  
Vue.config.productionTip = false  
App.mpType = 'app'  
const app = new Vue({  
    ...App  
})  
app.$mount()  
// #endif  

// #ifdef VUE3  
import {  
    createSSRApp  
} from 'vue'  
import * as Pinia from 'pinia';  

export function createApp() {  
    const app = createSSRApp(App)  
    app.use(Pinia.createPinia());  
    return {  
        app,  
        Pinia, // 此处必须将 Pinia 返回  
    }  
}  
// #endif

book.ts
import { ref } from 'vue'
import { defineStore } from 'pinia'
import type { IBook } from '../types/interface'

export const useBookStore = defineStore('book', () => {
const isDbOpen = ref(false)
const books = ref<IBook[]>([])

return { isDbOpen, books }  

})

使用:
import { useBookStore } from '../../stores/book'
const bookStore = useBookStore()

2024-11-09 12:06 负责人:无 分享
已邀请:
m***@meenw.com

m***@meenw.com (作者) - 夏天好热,冬天穿的又太多

???没人遇到过吗,只是声明一下都报错

1***@qq.com

1***@qq.com - 啦啦啦啦

我复制的之前的项目都报错,妈个鸡

要回复问题请先登录注册