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方法了。





  • 2017-02-09 09:02:26

    两列布局——左侧宽度固定,右侧宽度自适应的两种方法

     关于左侧宽度固定,右侧宽度自适应两列布局的一种很常用的方法我相信大家都知道。就是利用左侧元素浮动,或者绝对定位的方式使其脱离常规文档流,让两个块级元素能够在同一行显示。然后右侧元素 margin-left 的值等于左侧元素宽度,这时右侧元素将紧挨着左侧元素