Skip to content

修改数据

常见的修改数据有三种方式:

js
// 第一种修改方式,直接修改
countStore.sum = 666
// 第二种修改方式:批量修改
countStore.$patch({
   sum:666,
   school:"wahh",
   address:"河北"
});
// 第三种修改方式:借助action修改(action中可以编写一些业务逻辑)
countStore.increment(n.value);

store文件中的actions需要进行配置:

ts
// actions.里面放置的是一个一个的方法,用于响应组件中的“动付”
actions: {
    increment(value) {
        if (this.sum < 10) {
            console.log("increment被调用了", value);
            //修改数据 (this是当前的store)
            this.sum += value;
        }
    },
},

Released under the MIT License.