uniappvuex配置
时间: 2023-12-09 14:07:02 浏览: 27
以下是uni-app中vuex的配置方法:
1.安装vuex和vuex-persistedstate插件
```shell
npm install vuex vuex-persistedstate --save
```
2.在src目录下创建store目录,并在store目录下创建index.js文件
```javascript
import Vue from 'vue'
import Vuex from 'vuex'
import createPersistedState from 'vuex-persistedstate'
Vue.use(Vuex)
const store = new Vuex.Store({
state: {
// 状态
},
mutations: {
// 修改状态的方法
},
actions: {
// 异步操作的方法
},
plugins: [
createPersistedState({
storage: window.sessionStorage // 持久化存储到sessionStorage中
})
]
})
export default store
```
3.在main.js中引入store
```javascript
import Vue from 'vue'
import App from './App'
import store from './store'
Vue.config.productionTip = false
App.mpType = 'app'
const app = new Vue({
store,
...App
})
app.$mount()
```
相关推荐
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)