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

鍍金池/ 問答/動漫  HTML/ vue數(shù)據(jù)更新了,視圖沒有更新,但是在不刷新頁面的情況下子組件中調(diào)用create

vue數(shù)據(jù)更新了,視圖沒有更新,但是在不刷新頁面的情況下子組件中調(diào)用created,視圖就更新了,但是一刷新就又不更新了

功能是點擊多選框,切換表格的表頭數(shù)據(jù),在頁面中的data已經(jīng)定義好了,三個不同的表頭,
數(shù)據(jù)是更新了,就是試圖更新的是不完整的,比如有10列數(shù)據(jù),展示出來就只有5列,詭異的是,不刷新頁面的時候,我只要在子組件的created中隨便打印個什么,試圖就更新正常,但是一刷新就又缺失了。
我已經(jīng)試過了this.$set,不行。

<template>
<!--頁面中的選擇器-->
         <el-select v-model="sectionValue" placeholder="查看計劃" @change="changeData" >
              <el-option
                v-for="item in dateSection"
                :key="item.value"
                :label="item.label"
                :value="item.value">
              </el-option>
            </el-select>
<!--表格-->
        <table :columns="columnsData"
                   :columnsTable="columnsTier"
                   :table="dataSource">
        </table>
</template>
<script>
data(){
    return {
        columns:[
            {
                name:1,
                age:2,
            },
            {
                tierData:{
                   text:'多級表頭',
                   content:[
                       { 
                           name:1,
                           age:2,
                       }
                   ] 
                }
                
                
            },
        ],
        mColumns:['結(jié)構(gòu)和columns相同,就是少一個多級表頭的對象'],
        yColumns:['結(jié)構(gòu)和columns相同,就是少一個多級表頭的對象'],
        sColumns:['結(jié)構(gòu)和columns相同,就是少一個多級表頭的對象'],
    }
},
 computed:{
      columnsData(){
        return this.columns.filter(function(v){
          if(v.text !== undefined){
            return v
          }
        })
      },
      columnsTier(){
        return this.columns.filter(function(v){
          if(v.tierData !== undefined){
            return v
          }
        })
      },
}
methods:{
      changeData(value){
        console.log(value);
        if(!value){
          alert(0);
          return;
        }
        else if(value === '當月計劃'){
          alert(1)
          this.columns=this.mColumns
        }else if(value === '當季計劃'){
          alert(2)
           this.columns=this.sColumns
        }else if(value === '當年計劃'){
          alert(3)
          this.columns=this.yColumns
      },
}
</script>

子組件

子組件:
<template>
//部分視圖代碼不全,使用遍歷的方式,將數(shù)據(jù)循環(huán)出來
<el-table-column v-for="(list,index) in columns"
              :key="list.text"
              :label="list.text"
              :prop="list.dataIndex">
          <template scope="scope">
              {{scope.row[list.dataIndex]}}
          </template>
 </el-table-column>
</template>
<script>
Props:{
    // 接收父組件數(shù)據(jù)
      columns: {
        type: Array,
        default: function () {
          return []
        }
      },
      columnsTable: {
        type: Array,
        default: function () {
          return []
        }
      },
}
created(){
      console.log(this.columns); //打印出來是新數(shù)據(jù),單數(shù)不更新
      console.log(this.columnsTable);//打印出來是新數(shù)據(jù),單數(shù)不更新
},
</script>
回答
編輯回答
喜歡你

this.$nextTick(()=>{

this.$set(......)

})

2017年3月11日 19:11
編輯回答
澐染

你 key 等于一個隨機數(shù),當隨機數(shù)一樣的時候還是不行
還不如 v-for="(v, i) in xxx" :key="i"

2017年11月12日 12:51
編輯回答
孤慣

子組件中定義兩個變量來存從父組件傳過來的值,然后用watch監(jiān)聽columns、columnsTable這兩個值,在watch中給子組件中的變量賦值,試一下

2017年4月12日 23:44
編輯回答
爆扎

自問自答一下:這個原因處于element-ui的bug,具體的原因問百度,解決的方法就是:key='改成一個隨機函數(shù)Math.random()',就可以了

2017年7月21日 20:47