@wepy/x

2.1.0 • Public • Published

Vuex in WePY 2.0

Install

npm install @wepy/x vuex --save

Usage

  1. Install Vuex
// app.wpy
import wepy from '@wepy/core';
import vuex from '@wepy/x';

wepy.use(vuex);
  1. Initialize a store
// ~/store.js
import Vuex from '@wepy/x';

export default new Vuex.Store({
  state: {
    num: 0
  },
  mutations: {
    increment (state) {
      state.num++;
    }
  },
  actions: {
    increment ({ commit }) {
      commit('increment');
    },
    incrementAsync ({ commit }) {
      setTimeout(() => commit('increment'), 1000);
    }
  }
})
  1. Map to Component
// ~/counter.wpy
<template>
  <div> {{num}} </div>
  <button @tap="increment"> Increment </button>
  <button @tap="incrementAsync"> Increment Async </button>
</template>
<script>
import wepy from '@wepy/core';
import { mapState, mapActions } from '@wepy/x';

wepy.component({
  computed: {
    ...mapState([ 'num' ])
  },
  methods: {
    ...mapActions([ 'increment', 'incrementAsync' ])
  }
})

Document

https://vuex.vuejs.org/

Other

Vuex Module is not supportted currently. Check the Issue here.

Readme

Keywords

Package Sidebar

Install

npm i @wepy/x

Weekly Downloads

27

Version

2.1.0

License

MIT

Unpacked Size

4.89 kB

Total Files

5

Last publish

Collaborators

  • dlhandsome
  • gcaufy