SoFunction
Updated on 2025-04-03

Summary of the use of Element-UI+Vue mode

Project Framework

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

Embed vue uses <script>, but does not use vue-cli. Please paste the code in <template> into html by yourself and the code in <style> into the stylesheet.

Checkbox Select all or non-select all

&lt;template&gt;
  &lt;el-form-item label="Ground resistivity options:"&gt;
    &lt;el-checkbox class="search_item" v-model="eidAll" @change="handleEidAllChange"&gt;Select all&lt;/el-checkbox&gt;
    &lt;el-checkbox-group v-model=""&gt;
      &lt;el-checkbox class="search_item" v-for="item of eidList" :label=""&gt;{{  }}&lt;/el-checkbox&gt;
    &lt;/el-checkbox-group&gt;
  &lt;/el-form-item&gt;
&lt;/template&gt;

&lt;script&gt;
var app = new Vue({
  el: '#app',
  data: {
    // Select all variables    eidAll: false
    // checkbox single item    searchItem: {
      eid: [],
    },
    // checkbox data loop    eidList: [{
      name: 'Missing number',
      value: 'DZ1'
      // ...
    }]
  },
  methods: {
    // Select all processing    handleEidAllChange() {
      if () {
         = [];
        var arr = [];
        for (let i in ) {
          ([i].value);
        }
         = arr;
      } else {
         = [];
      }
    },
  },
  watch: {
    // Listen to checkboxes to select all    "": function() {
      if ( == ) {
         = true
      } else {
         = false
      }
    }
  }
});
&lt;/script&gt;

The head is fixed, the body is rolling

Plan ①: el-table, stuck, it is said to be related to the vue version, but it is still stuck after upgrading and abandoned.
Scheme ②: table, to set display:table; table-layout: fixed;, the layout has limitations.
Solution ③: div+el-col simulates table.

&lt;template&gt;
  &lt;div class="table"&gt;
    &lt;div class="thead"&gt;
      &lt;div class="tr"&gt;
        &lt;el-row&gt;
          &lt;el-col v-for="item of tableHeadList" :span=""&gt;
            &lt;div class="th"&gt;
              {{  }}
            &lt;/div&gt;
          &lt;/el-col&gt;
        &lt;/el-row&gt;
      &lt;/div&gt;
    &lt;/div&gt;
    &lt;div class="tbody"&gt;
      &lt;div class="tr" v-for="(item, index) of tableData"&gt;
        &lt;el-row&gt;
          &lt;el-col v-for="bodyItem of tableBodyList" :span=""&gt;
            &lt;div class="td"&gt;
              {{ item[] }}
            &lt;/div&gt;
          &lt;/el-col&gt;
        &lt;/el-row&gt;
      &lt;/div&gt;
    &lt;/div&gt;
  &lt;/div&gt;
&lt;/template&gt;

&lt;style&gt;
.table .tbody {
  width: 100%;
  height: 278px;
  overflow-y: scroll;
}
&lt;/style&gt;

&lt;script&gt;
var app = new Vue({
  el: '#app',
  data: {
    // th data loop    tableHeadList: [{
      // According to type, the title content of v-if th, and the text or checkbox should be placed according to the needs.      type: 'text',
      // Each grid occupies a grid, the total number of element-ui grids is 24      col: '1',
      // th title      text: 'ID'
    }],
    // td data loop    tableBodyList: [{
      type: 'text',
      col: '1',
      // The interface returns the field      field: 'id'
    }],
    // Table data    tableData: [...]
  }
});
&lt;/script&gt;

Table scrolling unlimited loading

You can use plug-ins, but just write them yourself for lightweight purposes. Use jQuery here.

&lt;script&gt;
var app = new Vue({
  el: '#app',
  mounted: function() {
    // Listen to scroll    ();
  },
  data: {
    // Load all data. Please initialize to false when changing the query conditions.    loadAll: false,
    // Page number, please initialize to 1 when changing the query conditions    offset: 1,
    // Table data, please clear it first when changing the query conditions    tableData: []
  },
  methods: {
    // Handle scroll loading    handleScrollLoad() {
      var $this = this

      var nScrollHight = 0;
      var nScrollTop = 0;
      var nDivHight = $(".table .tbody").height();
      $(".table .tbody").scroll(function() {
        if ($) {
          // No operation after all loading          return;
        }
        nScrollHight = $(this)[0].scrollHeight;
        nScrollTop = $(this)[0].scrollTop;
        if (nScrollTop + nDivHight &gt;= nScrollHight) {
          // Slide to the bottom, offset increment          // Because the offset defined by our backend is actually a page, which represents which page, not the true offset          // Those in need can convert to $ += $;          $ += 1;
          $()
        }
      });
    },
    // Query table data    searchData() {
      ...
      var $this = this
      (str)
      .then(res =&gt; {
        if ( === 200) {
          // The request is normal, and determine whether the complete loading is done          if ( === 0) {
            $ = true;
            return;
          }
          for (let i of ) {
            $(i);
          }
        } else {
          // Request error          alert('Request error, error code:' + );
        }
      }, e =&gt; {
         = false;
        throw new Error('Request failed:' + e);
      })
    }
  }
});
&lt;/script&gt;

Multiple echarts

Since vue is used, the best way to embed echarts is of course the component, encapsulate echarts into components, and then pass a v-for loop, and setOption every time the data is updated.

&lt;template&gt;
  &lt;div class="echarts_box"&gt;
    &lt;charts v-for="(item, index) of echartsData" :item="item"&gt;&lt;/charts&gt;
  &lt;/div&gt;
&lt;/template&gt;

&lt;script&gt;
var app = new Vue({
  el: '#app',
  data: {
    // Curve data    echartsData: []
  }
});

/************************ Curve Example************************/
('charts', {
  props: {
    item: Object
  },
  methods: {
    // Initialize the curve    initChart() {
      this['echart' + ()] = (('echart' + ));
      ();
    },
    setChart() {
     var $this = this
     let option = {
        ...
      };
      this['echart' + ].setOption(option);
    }
  },
  mounted() {
    ();
  },
  watch: {
   item: {
     handler: function () {
      ();
     },
     deep: true
   }
  },
  template: `&lt;div class="echart_item" : style="height:260px;"&gt;&lt;/div&gt;`
});
&lt;/script&gt;


postscript

I have been using this framework to do projects intermittently for a long time, and I have never summarized them specifically, which leads to the fact that I have to look up the previous code every time and recall it for a long time. For example, el-checkbox. Unlike other form items, its label is the real value. It is actually time-consuming to re-check the document + recall every time.

It is necessary to summarize the project routines. I think as working hours grow, whether a person improves or repeats his work is essentially related to whether he will summarize.

The above is all the content of this article. I hope it will be helpful to everyone's study and I hope everyone will support me more.