鍍金池/ 問答/HTML/ 我的這個vue的el組件prop渲染為什么渲染不上去呢?

我的這個vue的el組件prop渲染為什么渲染不上去呢?

table
<el-table

  :data="timeTable.courses"
  border
  style="width: 100%; margin-top: 20px"
  >
  <el-table-column
    prop ="time"         **prop接收的信息**
    label="時間"
    width="180">
  </el-table-column>
  <el-table-column
    prop ="course[0]"
    label="星期一">
  </el-table-column>
  <el-table-column
    prop ="course[1]"
    label="星期二">
  </el-table-column>
  <el-table-column
    prop ="course[2]"
    label="星期三">
  </el-table-column>
  <el-table-column
    prop ="course[3]"
    label="星期四">
  </el-table-column>
  <el-table-column
    prop ="course[4]"
    label="星期五">
  </el-table-column>
  <el-table-column
    prop ="course[5]"
    label="星期六">
  </el-table-column>
  <el-table-column
    prop ="course[6]"
    label="星期日">
  </el-table-column>
</el-table>

<script>

export default {

data() {
return {
  timeTable:{
      studentName:'格式化灰憶',
      class:'201705',
      term:'',
      courses:new Array(5),      **課程數(shù)組接收數(shù)組**
  }
};

},
mounted () {

const that = this;
this.$http.get(
  that.$interface+'queryClass?term=2016-2017-2'
)
  .then(function (response) {
    if(response.data!==false){
      for(var i = 0;i<5;i++){
                                   **數(shù)組的格式**
        that.timeTable.courses[i] = {time:(2*i+1) + ',' + (2*i+2),course:["","","","","","",""]};             
      }
      response.data.data.forEach(function(item){     **從后臺獲取數(shù)據(jù)遍歷**
        var temp = item.classTime.split('-');
        var row = (temp[1]- 1)/2;
        var col = temp[0] - 1;
        that.timeTable.courses[row].course[col] = item.course;
      });
      console.log(that.timeTable.courses);

    }else{
      that.$message({
        message: response.data.msg,
        type: 'warning'
      });
    }
  })
  .catch(function (err) {
    console.log(err);
    that.$message({
      message: '數(shù)據(jù) error',
      type: 'warning'
    })
  });

},
methods:{

}

}
</script>
打印出接收的數(shù)據(jù)信息

table格式?jīng)]有值渲染上去

回答
編輯回答
糖豆豆

data定義后往里面添加屬性不具有響應的特性。

試試不用'that.timeTable.courses[i] = '的形式

試試新創(chuàng)建一個數(shù)組,填充數(shù)據(jù)

最后讓 that.timeTable.courses = 新的數(shù)組

看看行不行

2017年9月25日 16:14
編輯回答
柒喵

看你的代碼好像初始化的時候 timeTable.courses[index] 里面并沒有聲明 course 屬性,你可以用 this.$set對數(shù)據(jù)進行賦值再試試

2017年2月7日 12:02