123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990 |
- import {
- getCode
- } from '@/api/test/index.js'
- export default {
- namespaced: true, //命名空间必须写
- state: {
- // 第一个页面参数
- testInfo: 'testInfotestInfotestInfotestInfo',
- testInfo2: '',
- switchs: [1, 0, 0]
- // 持久化常用参数
- // token: uni.getStorageSync('vuex').token, // token
- },
- getters: {
- testInfo(state) {
- return state.testInfo;
- },
- testInfo2(state) {
- return state.testInfo2;
- },
- testInfo3(state) {
- return state;
- },
- testInfo4(state) {
- return state.switchs;
- }
- },
- //唯一修改state值的方法
- // commit
- mutations: {
- testMut(state, data) {
- state.testInfo = data
- },
- testMut2(state, data) {
- state.testInfo2 = data
- },
- testMut3(state) {
- state.testInfo = '',
- state.testInfo2 = ''
- },
- testMut4(state, data) {
- state.switchs = data
- }
- },
- // 异步的操作
- // dispatch
- actions: {
- testAct({
- commit
- }, payload) {
- commit('testMut', payload)
- },
- // 登陆,持久化存储token,id
- testAct2(context, payload) {
- return new Promise(async (resolve, reject) => {
- getCode(payload).then(res => {
- const {
- code,
- msg,
- data
- } = res
- if (code == 0) {
- context.commit('testMut2', msg)
- resolve(res)
- } else {
- // reject(res)
- resolve(res)
- }
- }).catch(err => {
- reject(err)
- })
- })
- },
- testAct3({
- commit
- }) {
- console.log('jinrul-------------testAct3 ');
- commit('testMut3')
- },
- testAct4({
- commit
- }) {
- console.log('jinrul-------------testAct3 ');
- commit('testMut3')
- },
- },
- }
|