具体配置
// 这里千万不要引入 import { createApp } from 'vue' 和 Vue.use(Vuex)
import { createStore } from 'vuex'
import cart from "@/store/modules/cart.js"
import my from "@/store/modules/my.js"
export default createStore({
modules: {
cart,
my
}
})
const getDefaultState = () => {
return {
// token: getToken(),
name: 'aaaaa',
}
}
const state = getDefaultState()
export default {
state
}
import App from './App'
// #ifndef VUE3
import Vue from 'vue'
import './uni.promisify.adaptor'
import { createApp } from 'vue'
import store from 'store/index.js'
const app = createApp(App) // 创建 app
app.use(store) // 挂载 store
app.mount('#app')
// Vue.config.productionTip = false
// #endif
// #ifdef VUE3
import {
createSSRApp
} from 'vue'
export function createApp() {
const app = createSSRApp(App)
return {
app
}
}
// #endif
<script setup>
import store from '@/store/index.js'
console.log(store.state.cart.name); // 直接可以访问 当然也可以使用计算属性
</script>