欧美大屁股bbbbxxxx,狼人大香伊蕉国产www亚洲,男ji大巴进入女人的视频小说,男人把ji大巴放进女人免费视频,免费情侣作爱视频

歡迎來到入門教程網!

JavaScript

當前位置:主頁 > 網絡編程 > JavaScript >

Element-UI+Vue模式使用總結

來源:本站原創(chuàng)|時間:2020-01-10|欄目:JavaScript|點擊: 次

項目框架

Element-ui+Vue+jQuery+Bootstrap+Echarts。

嵌入vue使用的是<script>,沒有使用vue-cli,請自行將<template>內代碼貼入html,<style>內代碼貼入樣式表。

checkbox全選和全不選

<template>
  <el-form-item label="地電阻率選項:">
    <el-checkbox class="search_item" v-model="eidAll" @change="handleEidAllChange">全選</el-checkbox>
    <el-checkbox-group v-model="searchItem.eid">
      <el-checkbox class="search_item" v-for="item of eidList" :label="item.value">{{ item.name }}</el-checkbox>
    </el-checkbox-group>
  </el-form-item>
</template>

<script>
var app = new Vue({
  el: '#app',
  data: {
    // 全選變量
    eidAll: false
    // checkbox單項
    searchItem: {
      eid: [],
    },
    // checkbox數(shù)據(jù)循環(huán)
    eidList: [{
      name: '缺數(shù)',
      value: 'DZ1'
      // ...
    }]
  },
  methods: {
    // 處理全選
    handleEidAllChange() {
      if (this.eidAll) {
        this.searchItem.eid = [];
        var arr = [];
        for (let i in this.eidList) {
          arr.push(this.eidList[i].value);
        }
        this.searchItem.eid = arr;
      } else {
        this.searchItem.eid = [];
      }
    },
  },
  watch: {
    // 監(jiān)聽checkbox是否全部選擇
    "searchItem.eid": function() {
      if (this.searchItem.eid.length == this.eidList.length) {
        this.eidAll = true
      } else {
        this.eidAll = false
      }
    }
  }
});
</script>

表頭固定,表身滾動

方案①:el-table,卡死,據(jù)說和vue版本有關系,但是升級了仍然卡死,拋棄。
方案②:table,要設置display:table; table-layout: fixed;,布局有局限性。
方案③:div+el-col模擬table。

<template>
  <div class="table">
    <div class="thead">
      <div class="tr">
        <el-row>
          <el-col v-for="item of tableHeadList" :span="item.col">
            <div class="th">
              {{ item.text }}
            </div>
          </el-col>
        </el-row>
      </div>
    </div>
    <div class="tbody">
      <div class="tr" v-for="(item, index) of tableData">
        <el-row>
          <el-col v-for="bodyItem of tableBodyList" :span="bodyItem.col">
            <div class="td">
              {{ item[bodyItem.field] }}
            </div>
          </el-col>
        </el-row>
      </div>
    </div>
  </div>
</template>

<style>
.table .tbody {
  width: 100%;
  height: 278px;
  overflow-y: scroll;
}
</style>

<script>
var app = new Vue({
  el: '#app',
  data: {
    // th數(shù)據(jù)循環(huán)
    tableHeadList: [{
      // 根據(jù)type來v-if th的標題內容,根據(jù)需求放文本或checkbox
      type: 'text',
      // 每格占用柵格,element-ui總柵格數(shù)是24
      col: '1',
      // th標題
      text: 'ID'
    }],
    // td數(shù)據(jù)循環(huán)
    tableBodyList: [{
      type: 'text',
      col: '1',
      // 接口返回字段
      field: 'id'
    }],
    // 表格數(shù)據(jù)
    tableData: [...]
  }
});
</script>

表格滾動無限加載

可以用插件,但為了輕量就自己寫吧,此處用jQuery。

<script>
var app = new Vue({
  el: '#app',
  mounted: function() {
    // 監(jiān)聽滾動
    this.handleScrollLoad();
  },
  data: {
    // 加載完全部數(shù)據(jù),更換查詢條件時請先初始化為false
    loadAll: false,
    // 頁碼,更換查詢條件時請先初始化為1
    offset: 1,
    // 表格數(shù)據(jù),更換查詢條件時請先清空
    tableData: []
  },
  methods: {
    // 處理滾動加載
    handleScrollLoad() {
      var $this = this

      var nScrollHight = 0;
      var nScrollTop = 0;
      var nDivHight = $(".table .tbody").height();
      $(".table .tbody").scroll(function() {
        if ($this.loadAll) {
          // 全部加載完不進行操作
          return;
        }
        nScrollHight = $(this)[0].scrollHeight;
        nScrollTop = $(this)[0].scrollTop;
        if (nScrollTop + nDivHight >= nScrollHight) {
          // 滑到底部,offset遞增
          // 因為我們后端定義的offset其實是page,代表第幾頁,而不是真正意義上的offset
          // 有需要的人可以轉為$this.offset += $this.limit;
          $this.offset += 1;
          $this.searchData()
        }
      });
    },
    // 查詢表格數(shù)據(jù)
    searchData() {
      ...
      var $this = this
      axios.get(str)
      .then(res => {
        if (res.status === 200) {
          // 請求正常,判斷是否加載完全部
          if (res.data.rows.length === 0) {
            $this.loadAll = true;
            return;
          }
          for (let i of res.data.rows) {
            $this.tableData.push(i);
          }
        } else {
          // 請求錯誤
          alert('請求錯誤,錯誤碼:' + res.status);
        }
      }, e => {
        this.loading = false;
        throw new Error('請求失?。? + e);
      })
    }
  }
});
</script>

多個echarts

既然使用了vue,嵌入echarts最好的方式當然是組件,將echarts封裝成組件,再通過v-for循環(huán),每次數(shù)據(jù)更新再setOption。

<template>
  <div class="echarts_box">
    <charts v-for="(item, index) of echartsData" :item="item"></charts>
  </div>
</template>

<script>
var app = new Vue({
  el: '#app',
  data: {
    // 曲線數(shù)據(jù)
    echartsData: []
  }
});

/*****************************曲線實例****************************/
Vue.component('charts', {
  props: {
    item: Object
  },
  methods: {
    // 初始化曲線
    initChart() {
      this['echart' + (this.item.id)] = echarts.init(document.getElementById('echart' + this.item.id));
      this.setChart();
    },
    setChart() {
     var $this = this
     let option = {
        ...
      };
      this['echart' + this.item.id].setOption(option);
    }
  },
  mounted() {
    this.initChart();
  },
  watch: {
   item: {
     handler: function () {
      this.setChart();
     },
     deep: true
   }
  },
  template: `<div class="echart_item" :id="'echart'+item.id" style="height:260px;"></div>`
});
</script>


后記

使用這個框架做項目斷斷續(xù)續(xù)也做了很久了,一直都沒有特意去總結,導致每次都要翻從前的代碼,回憶良久,例如el-checkbox,不同于其他表單項,它的label才是真正的value,每次都要重新查閱文檔+回憶,其實是很費時的。

總結項目 是很有必要的,我覺得隨著工作時間增長,一個人是進步,還是重復工作,和會不會總結有本質聯(lián)系。

以上就是本文的全部內容,希望對大家的學習有所幫助,也希望大家多多支持我們。

上一篇:JS實現(xiàn)導航欄樓層特效

欄    目:JavaScript

下一篇:Angular8 實現(xiàn)table表格表頭固定效果

本文標題:Element-UI+Vue模式使用總結

本文地址:http://mengdiqiu.com.cn/a1/JavaScript/9326.html

網頁制作CMS教程網絡編程軟件編程腳本語言數(shù)據(jù)庫服務器

如果侵犯了您的權利,請與我們聯(lián)系,我們將在24小時內進行處理、任何非本站因素導致的法律后果,本站均不負任何責任。

聯(lián)系QQ:835971066 | 郵箱:835971066#qq.com(#換成@)

Copyright © 2002-2020 腳本教程網 版權所有