Home > Web Front-end > uni-app > Can uniapp use vuex?

Can uniapp use vuex?

coldplay.xixi
Release: 2020-12-17 10:22:57
Original
4855 people have browsed it

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.

Can uniapp use 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
Copy after login

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()
Copy after login

4. Use vuex in a single page

<script>
    export default {
        created () {
            console.log(this.$store)
        }
    }
</script>
Copy after login

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!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template