在线观看不卡亚洲电影_亚洲妓女99综合网_91青青青亚洲娱乐在线观看_日韩无码高清综合久久

鍍金池/ 問答/HTML/ computed數(shù)據(jù)改變了卻沒有更新到視圖中

computed數(shù)據(jù)改變了卻沒有更新到視圖中

使用計(jì)算屬性computed,監(jiān)控?cái)?shù)據(jù),實(shí)現(xiàn)表頭的切換,現(xiàn)在的問題是,計(jì)算屬性中的數(shù)據(jù)更新了,卻沒有更新到視圖中

//data中定義好的3個(gè)表頭
data(){
    return {
        columns:[
          {text:'總', dataIndex:'total'},
        ],
        yColumns:[
          {text:'年', dataIndex:'year'},
        ],
        mColumns:[
          {text:'月', dataIndex:'month'},
        ],
    }
}

//定義的計(jì)算屬性
    computed:{
      columnsData(){
        console.log(this.columns.filter(function (v) {
          if (v.text !== undefined) {
            return v
          }
        }));
        return this.columns.filter(function(v){
          if(v.text !== undefined){
            return v
          }
        })
      }
    },
    
    methods:{
    //      按名稱切換表頭
      changeData(value){
        if(!value){
          alert(0);
          return;
        }
        else if(value === '當(dāng)月'){
          alert(1)
          this.columns=this.mColumns
        }else if(value === '當(dāng)年'){
          alert(3)
          this.columns=this.yColumns;
        }
      },
    }
回答
編輯回答
命多硬

https://cn.vuejs.org/v2/guide...

需要仔細(xì)看一下computed的文檔。
他會(huì)對(duì)屬性進(jìn)行緩存,只有在外部的屬性值改變時(shí)才會(huì)發(fā)生改變。

需要另外寫一個(gè)set函數(shù)

2017年7月5日 16:02
編輯回答
懷中人

雖然不能看出什么,但是看起來更像是Array.prototype.filter使用的有點(diǎn)不當(dāng)啊,至少這樣看起來正常點(diǎn):

this.columns.filter(function (v) {
            return v.text !== undefined;
        })
2017年12月24日 18:32
編輯回答
尕筱澄

麻煩貼一段,你視圖的代碼吧

2018年1月19日 20:22