点击页面加载后如何呈现组件数据

时间:2019-07-06 08:46:41

标签: vue.js laravel-5 vue-component

我在laravel中使用vue js。我想根据点击的日期重新加载数据。

我从api获取的数据是按日期获取的,但前面没有变化

这是我的app.js代码下的

var socket = new Vue({
  el: "#enrollment-app",
  components: {
    barChart
  },
  data: {
    privateChannleData: null,
    exam_type: null,
    exam_id: null,
    response_exam_data: [],
    response_lap_data: [],
    response_btn_list: [],
    student_list: [],
    lineChartData: {
      lables: [],
      options: [],
      dataset: []
    }
  },
  created() {

    if (document.getElementById("exam_type"))
      this.exam_type = document.getElementById("exam_type").value;

    if (document.getElementById("exam_id"))
      this.exam_id = document.getElementById("exam_id").value;

    if (this.exam_type != null && this.exam_id != null)
      this.getEnrollmentStatus();
  },
  methods: {

    getEnrollmentStatus: function(date="null") {
      var self = this;
      var data_set = [];
      var params = {
        exam_type: document.getElementById("exam_type").value,
        exam_id: document.getElementById("exam_id").value,
        date:date,
      };

      console.log(params);
      axios
        .post("/api/get_enrollment_data", params)
        .then(function(response) {
          self.response_exam_data = response.data.data;
          //console.log(self.response_exam_data.students[0]);
          self.response_exam_data.students[0].forEach(function(ii, vv) {
            self.student_list.push(ii);
          });

            self.response_btn_list=self.response_exam_data.articles[0];   
          self.lineChartData.dataset = {
            labels: [
              "Total Enrollment",
              "Not Submitted",
              "Submitted",
              "Total Pass",
              "Total Fail"
            ],
            datasets: [
              {
                label: "Enrollment Data",
                backgroundColor: "#f87979",
                data: [
                  parseInt(self.response_exam_data.total_enrollment),
                  parseInt(self.response_exam_data.not_submitted),
                  parseInt(self.response_exam_data.submitted_count),
                  parseInt(self.response_exam_data.total_pass),
                  parseInt(self.response_exam_data.total_fail)
                ]
              }
            ]
          };
          self.lineChartData.options = {
            scales: {
              yAxes: [
                {
                  ticks: {
                    beginAtZero: true
                  }
                }
              ]
            },
            responsive: true,
            maintainAspectRatio: true
          };
        })
        .catch(function(error) {
          alert("Error. Try again after sometime.");
        });
    }
  },

});

这是我的html代码下的内容。

<div id="enrollment-app">
    <button v-for="(button, key)  in response_btn_list" type="button" v-on:click="getEnrollmentStatus({{ button }})" class="btn btn-success btn-icon left-icon  mr-10" :date="button">lap @{{ key+1 }} </button>
    <div class="user-data">
        <span class="name block capitalize-font">@{{student.name}}</span>
        <span class="time block" style="width:400px;">                                                                                    Status:- <span class="txt-primary">@{{student.status_text}} </span> Rank:- <span class="txt-primary">@{{student.My_rank}}</span> Time Taken:- <span class="txt-primary">@{{student.timeTaken}}</span><br/>
          Result:- <span class="txt-primary">@{{student.final_result}}</span>
          Total Marks:- <span class="txt-primary">@{{student.total_marks}}</span>
          Obtained Marks:- <span class="txt-primary">@{{student.obtained_marks}}</span>
        </span>
        <div :class="student.status"></div>
        <div class="clearfix"></div>
    </div>
</div>

我在页面上加载的结果数据

Sum

单击按钮后我得到的数据

image on laad data

我只想在前端渲染数据。

0 个答案:

没有答案