<> one , use vuex
<>1. install vuex
npm install vuex@next --save
<>2. use vuex
from vue You can learn from the official website vue3 use vuex The method of .
<>2.1src New file under store
new file index.js
<>2.2 to configure store
import { createStore } from "vuex"; // Create status const state = { } // establish actions const
actions= { } // establish mutataions const mutations = { } // establish store const store =
createStore({ state, actions, mutations }) // Exposed export default store
<>2.3 Add to vue Medium app
import { createApp } from 'vue' import App from './App.vue' import store from
'./store/index' createApp(App).use(store).mount('#app')
<>2.4 use store
First introduce in the component
import { useStore } from 'vuex'
stay setup Used in useStore That's right store Operate
It is better to create a new variable directly , Easy to operate
const store = useStore();
From the overall code , Import an attachment hook to check whether it is imported
import { onMounted } from '@vue/runtime-core'; import { useStore } from 'vuex'
export default { name: 'HelloWorld', props: { msg: String }, setup(){ const
store= useStore(); onMounted(()=>{ console.log(store) }) } }
Console view ,store Indeed introduce , You can proceed to the next step .
Technology