vuex 设置state时的骚操作,批量设置state

2020-11-11 15:08:52

vuex 设置state时的骚操作,批量设置state

uex mutations 代码

state: {
    showLaser:true,  
    showPath:true,  
    showCamera:true,  

  },mutations: {
    setState(state,opt){
      for(let [key,val] of Object.entries(opt)){
        state[key] = val;
      }
    }
 }

使用

this.$store.commit('setState',{
        showLaser:false,
        showCamera:false,
        showPath:false,})

这样就不要每次设置state值时写一个对应的更新state方法了。





  • 2021-05-25 13:10:49

    npm 多个不同版本的依赖

    提起 npm,大家第一个想到的应该就是 npm install 了,但是 npm install 之后生成的 node_modules 大家有观察过吗?package-lock.json 文件的作用大家知道吗?除了 dependencies 和 devDependencies,其他的依赖有什么作用呢?接下来,本文将针对 npm 中的你可能忽略的细节和大家分享一些经验 。