使用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()
2 个回复
m***@meenw.com (作者) - 夏天好热,冬天穿的又太多
???没人遇到过吗,只是声明一下都报错
1***@qq.com - 啦啦啦啦
我复制的之前的项目都报错,妈个鸡