vant 步进器值步动态改变

这里如何让我的值动态修改呢
1.通过getters 函数获得 : 在mounted 可以显示 在 标签里面无法显示
2.直接获得orderCount的属性: 值不更新 (测试修改值会更新 两层map 不更新)
3.直接弄一层map 试一试 getOrderAndCount 只是获取第一次的初值 我后面添加的订单冒得
4.重新建立一个orderAndCount 问题解决

微信小程序有数据更新有时延问题,但是appData 不会延时

<van-stepper :value="getOrderAndCount[item.id]" ref="stepper" slot="right-icon"  min="0" max="99" @plus="addOrder({id:item.id,price:item.price,name:item.name})" @minus="subOrder(item.id)" />



   computed:{
      ...mapState(['order']),
      ...mapGetters(['getOrders',"getOrderCountById",'test','getOrderAndCount']),
    },
  • store.js
import Vue from 'vue'
import Vuex from 'vuex'
import order from '../datas/order'
// import state from './state'
// import actions from './actions'
// import mutations from './mutations'
// import getters from './getter'


// 声明使用vuex
Vue.use(Vuex)

export default new Vuex.Store({
  state:{
    order:{
      1:{price:12,count:10,name:"coco"},
      2:{price:12,count:10,name:"coco"}
    },
    orderAndCount:{
      1:10,2:10
    }
  },
  mutations:{
    addOrder: function (state, params) {
      // console.log(params);
      if (!state.order[params.id]) {
        state.order[params.id] = {count: 1, name: params.name, price: params.price}
        state.orderAndCount[params.id] = 1;
      } else {
        state.order[params.id]['count']++;
        state.orderAndCount[params.id]++;
      }
      console.log("addOrder:")
      console.log(state.order)
    },
    subOrder(state,id){
      if(state.order[id]['count']>1){
        state.order[id]['count']--
        state.orderAndCount[id]--;
      }else{
        delete state.order[id]
        delete state.orderAndCount[id];
      }
      console.log("subOrder:")
      console.log(state.order)
    }
  },
  getters:{
    getOrders(state){
      return state.order;
    },
    getOrderCountById(state,getters){
      return function (id) {
        if (state.order[id]) {
          return state.order[id].count;
        } else {
          return 0;
        }
      }
    },
    test(state,getters){
      return function (id) {
        return id*2;
      }
    },
    //获得总价
    getTotalPrice(state){
        let totalPrice = 0;
        for(let key in state.order){
            totalPrice += state.order[key].price * state.order[key].count;
        }
        return totalPrice*100;
    },
    getOrderAndCount(state){
      return state.orderAndCount;
    }

  }

})

你可能感兴趣的:(解决方案)