Gcaufy b3143aa748 release: @wepy/x@2.1.1-alpha.0 | il y a 4 ans | |
---|---|---|
.. | ||
dist | il y a 4 ans | |
CHANGELOG.md | il y a 4 ans | |
README.md | il y a 4 ans | |
README_EN.md | il y a 4 ans | |
index.js | il y a 4 ans | |
package-lock.json | il y a 4 ans | |
package.json | il y a 4 ans |
English | 简体中文
npm install @wepy/x vuex --save
// app.wpy
import wepy from '@wepy/core';
import vuex from '@wepy/x';
wepy.use(vuex);
// ~/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);
}
}
})
// ~/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' ])
}
})