uniapp can use vuex. How to use it: first create a folder named store, define public data and methods under the js file; then mount vuex in the entry file; finally use it in a single page vuex.
The operating environment of this tutorial: windows7 system, uni-app2.5.1 version. This method is suitable for all brands of computers.
Recommended (free): uni-app development tutorial
uniapp can use vuex, usage method:
1. In the root directory of the project, create a folder named store and then create a js file index.js under the folder
2. Define public data and methods under the js file. And export it
import Vue from 'vue' import Vuex from 'vuex' Vue.use(Vuex) const store = new Vuex.Store({ state: {}, mutations: {}, actions: {} }) export default store
3. Mount vuex in the entry file: main.js
import Vue from 'vue' import App from './App' //引入vuex import store from './store' //把vuex定义成全局组件 Vue.prototype.$store = store Vue.config.productionTip = false App.mpType = 'app' const app = new Vue({ ...App, //挂载 store }) app.$mount()
4. Use vuex in a single page
<script> export default { created () { console.log(this.$store) } } </script>
Related Free learning recommendations: php programming (video)
The above is the detailed content of Can uniapp use vuex?. For more information, please follow other related articles on the PHP Chinese website!