在main.js中注册
// vue2的vuex
// #ifdef VUE3
import store from './store/index.js'
import {
createSSRApp
} from 'vue'
export function createApp() {
const app = createSSRApp(App)
app.use(store)
return {
app
}
}
// #endif
创建一个store的文件夹 创建 index.js的store文件
// 页面路径:store/index.js
import {
createStore
} from 'vuex'
const store = createStore({
state: { //存放状态
"username": "foo",
"age": 18,
"cart": ['迪丽热巴'],
todos: [{
id: 1,
text: '我是内容一',
done: true
},
{
id: 2,
text: '我是内容二',
done: true
}
],
count: 1