Detailed explanation of the steps of using ElementUI in actual projects

Detailed explanation of the steps of using ElementUI in actual projects

1. Table self-sorting

Objective: Click the up and down arrows after the employment date to sort the data on the current page in ascending or descending order according to the employment date

Idea: Add sortable to el-table-column

Sorting is to sort the retrieved data, only on the front end.

Reference: https://element.eleme.io/#/zh-CN/component/table#pai-xu

Code implementation (reference):

<!-- 1. Define the field name that needs to be sorted by field-->
 
<el-table :data="list" border :default-sort="{prop: 'workNumber'}">
</el-table>
 
<!-- 2. Ensure that the prop attribute and sortable attribute are declared on the field column -->
 
<el-table-column label="Job Entry Time" sortable prop="timeOfEntry">
</el-table-column>

2. Paging function

Goal (effect): Implement paging data acquisition logic

Idea: Just configure according to the property requirements of the paging component.

step:

Step 1: Supplementary data items

According to the requirements of the el-pagination component, add paging-related data items to the page

data() {
  return {
    //Omit other total: 0,
    page: 1, // current page number size: 5, // number of records per page total: 0 // total number of records }
}

Step 2: Paging Structure

<div style="height: 60px; margin-top: 10px">
<!-- Pagination -->
        <el-pagination
          layout="total, sizes,prev, pager, next, jumper"
          :total="total"
          :page-size="size"
          :page-sizes="[2,5,10]"
          @current-change="hCurrentChange"
          @size-change="hSizeChange"
        />
</div>

Step 3: Implement paging logic

// Will automatically receive the currently clicked page number hCurrentChange(curPage) {
      // alert(curPage)
      // 1. Update the page number this.page = curPage
      // 2. Resend request this.loadEmployee()
    },
    // How many items per page hSizeChange(curSize) {
      // alert(size)
      // 1. Update the number of entries per page this.size = curSize
      // 2. Resend request this.loadEmployee()
    },

3.el-checkbox-group multiple-selection box

Effect

Precautions for use:

For el-checkbox-group used to indicate multiple selections:

The value of v-model is an array (indicating multiple selections)

The label attribute of its child element el-checkbox determines the value after selecting this item.

template

<el-checkbox-group v-model="roleIds">
  <el-checkbox label="110">Administrator</el-checkbox>
  <el-checkbox label="113">Developer</el-checkbox>
  <el-checkbox label="115">Personnel</el-checkbox>
</el-checkbox-group>

data

data () {
  return {
    roleIds: [] // Save the currently selected permission list}
}

4. Encapsulate the calendar component

Effect:

Idea: This component is relatively large (there is also a lot of code in the homepage), so we will propose it as a separate component

Step 1: Encapsulate a component (register, introduce and use three steps)

Step 2: Use the Calendar component on your home page

<el-card class="box-card">
  <div slot="header" class="header">
    <span>Work Calendar</span>
  </div>
  <!-- Place the calendar component-->
  <calender />
</el-card>

Step 3: Customize the calendar content display with slots

<template>
  <el-calendar v-model="currentDate">
    <template slot="dateCell">
      <div class="date-content">
        <span class="text">01</span>
        <span class="rest">rest</span>
      </div>
    </template>
  </el-calendar>
</template>
 
<script>
export default {
  data() {
    return {
      curDate: new Date()
    }
  }
}
</script>

5. Implement radar chart using antv-G2

Effect:

This kind of graph is also available in echarts. Here we use antv-G2, a product of the Ant Data Visualization Department.

https://antv.vision/en

https://g2.antv.vision/en/examples/radar/radar#basic

Step 1: Install necessary dependencies

npm install @antv/data-set @antv/g2

Step 2: Create a component to implement the radar chart

The following code is referenced from the official website: https://g2.antv.vision/zh/examples/radar/radar#basic

<template>
  <div id="container" />
</template>
 
<script>
import DataSet from '@antv/data-set'
import { Chart } from '@antv/g2'
export default {
  mounted() {
    const data = [
      { item: 'Work efficiency', a: 70, b: 30 },
      { item: 'Attendance', a: 60, b: 70 },
      { item: 'Positiveness', a: 50, b: 60 },
      { item: 'Helping a colleague', a: 40, b: 50 },
      { item: 'Self-directed learning', a: 60, b: 70 },
      { item: 'Accuracy', a: 70, b: 50 }
    ]
    const { DataView } = DataSet
    const dv = new DataView().source(data)
    dv.transform({
      type: 'fold',
      fields: ['a', 'b'], // Expand field set key: 'user', // key field value: 'score' // value field })
 
    const chart = new Chart({
      container: 'container',
      autoFit: true,
      height: 500
    })
    chart.data(dv.rows)
    chart.scale('score', {
      min: 0,
      max: 80
    })
    chart.coordinate('polar', {
      radius: 0.8
    })
    chart.tooltip({
      shared: true,
      showCrosshairs: true,
      crosshairs:
        line: {
          style: {
            lineDash: [4, 4],
            stroke: '#333'
          }
        }
      }
    })
    chart.axis('item', {
      line: null,
      tickLine: null,
      grid: {
        line: {
          style: {
            lineDash: null
          }
        }
      }
    })
    chart.axis('score', {
      line: null,
      tickLine: null,
      grid: {
        line: {
          type: 'line',
          style: {
            lineDash: null
          }
        }
      }
    })
 
    chart
      .line()
      .position('item*score')
      .color('user')
      .size(2)
    chart
      .point()
      .position('item*score')
      .color('user')
      .shape('circle')
      .size(4)
      .style({
        stroke: '#fff',
        lineWidth: 1,
        fillOpacity: 1
      })
    chart
      .area()
      .position('item*score')
      .color('user')
    chart.render()
  }
}
</script>

6. Multi-language support

Effect: vue-i18n is used for multi-language support in Vue projects

Reference: https://kazupon.github.io/vue-i18n/zh/started.html

Objective: Implement the Chinese-English switching function of elementUI and experience the effect of Chinese switching

Step 1: Install international packages

Step 2: ElementUI multi-language configuration

Import the element language package file src/lang/index.js

//Configure multi-language support import Vue from 'vue' //Introduce Vue
import VueI18n from 'vue-i18n' // Import international plug-in package import locale from 'element-ui/lib/locale'
import elementEN from 'element-ui/lib/locale/lang/en' // Import the English package of Ele.me import elementZH from 'element-ui/lib/locale/lang/zh-CN' // Import the Chinese package of Ele.me Vue.use(VueI18n) // Globally register internationalization package // Create an instance of the internationalization plug-in const i18n = new VueI18n({
  //Specify the language type zh for Chinese en for English locale: 'zh',
  // Add the elementUI language pack to the plugin language data messages: {
    // Language data in English environment en: {
      ...elementEN
    },
    // Language data in Chinese environment zh: {
      ...elementZH
    }
  }
})
// Configure elementUI language conversion relationship locale.i18n((key, value) => i18n.t(key, value))
 
export default i18n

This is the end of this article about the functional summary of ElementUI used in actual projects. For more relevant ElementUI project usage summary content, please search for previous articles on 123WORDPRESS.COM or continue to browse the related articles below. I hope everyone will support 123WORDPRESS.COM in the future!

You may also be interested in:
  • How to use webpack to output MPA in Vue+ElementUI project
  • How to view the elementUI version currently used in the Vue project
  • How to create a project with Vue3+elementui plus
  • Detailed explanation of how to introduce elementUI components into vue projects
  • Use ElementUI Tree tree control and add icons to nodes
  • Detailed explanation of the use of vue+elementUi image upload component
  • vue elementUI uses tabs to link with the navigation bar
  • Detailed explanation of the use and precautions of elementUI select component

<<:  Detailed explanation of docker network bidirectional connection

>>:  Mybatis implements SQL query interception and modification details

Recommend

Nginx domain forwarding usage scenario code example

Scenario 1: Due to server restrictions, only one ...

Javascript Basics: Detailed Explanation of Operators and Flow Control

Table of contents 1. Operator 1.1 Arithmetic oper...

js implements single click to modify the table

Pure js implements a single-click editable table ...

Example of adding and deleting range partitions in MySQL 5.5

introduce RANGE partitioning is based on a given ...

Solution to the timeout problem when installing docker-compose with PIP

1: Installation command pip install docker-compos...

Detailed tutorial on using the Prettier Code plugin in vscode

Why use prettier? In large companies, front-end d...

Slot arrangement and usage analysis in Vue

The operating environment of this tutorial: Windo...

Detailed explanation of Tomcat's commonly used filters

Table of contents 1. Cross-domain filter CorsFilt...

JavaScript canvas realizes the effect of nine-square grid cutting

This article shares the specific code of canvas t...

An example of how to implement an adaptive square using CSS

The traditional method is to write a square in a ...

A brief discussion of 12 classic problems in Angular

Table of contents 1. Please explain what are the ...

How to build lnmp environment in docker

Create a project directory mkdir php Create the f...

What I learned while building my own blog

<br />In one year of blogging, I have person...