一、安装vuex
npm i vuex@4
二、配置vuex
src
Ⅼstore
Ⅼindex.js
store/index.js
// store/index.js
import {createStore} from 'vuex'
export default createStore({
state: {
uccu:{1: null},
},
mutations: {
},
actions: {
},
})
三、main.js 引入
main.js
中引入
//main.js
import store from './store'
const app = createApp(App)
app.use(store)
四、其它组件中使用
import {useStore} from 'vuex'
export default {
name: "XXXX",
setup(props, context){
const store = useStore()
// ....
return {
//...
}
}
}