Home > Web Front-end > Vue.js > Tips on using common Vue UI components

Tips on using common Vue UI components

WBOY
Release: 2023-06-25 08:31:50
Original
1426 people have browsed it

In modern web development, UI components are an integral part. There are many excellent UI component libraries in the Vue.js framework, such as Element-UI, Vuetify, Ant Design Vue, etc. These component libraries provide many easy-to-use components that can help us create web applications more efficiently. This article will introduce some commonly used Vue UI components, as well as tips and practical skills for using these components.

1. El-Table

El-Table is one of the most practical components in ElementUI. It provides an intuitive way to display and manipulate tabular data. Here are some tips for using El-Table:

1. Enable table paging

Paging is necessary when processing large amounts of data. You can use the paging function that comes with the El-Table component to ease the data Loading problem. The following is a simple paging example:

<template>
  <el-table
    :data="tableData"
    :height="400"
    :pagination="pagination"
  >
    <el-table-column
      prop="date"
      label="日期"
      width="180"
    ></el-table-column>
    <el-table-column
      prop="name"
      label="姓名"
      width="180"
    ></el-table-column>
    <el-table-column
      prop="address"
      label="地址"
    ></el-table-column>
  </el-table>
</template>

<script>
export default {
  data() {
    return {
      tableData: [
        { date: '2016-05-02', name: '王小虎', address: '上海市普陀区金沙江路 1518 弄' },
        { date: '2016-05-04', name: '王小虎', address: '上海市普陀区金沙江路 1517 弄' },
        { date: '2016-05-01', name: '王小虎', address: '上海市普陀区金沙江路 1519 弄' },
        { date: '2016-05-03', name: '王小虎', address: '上海市普陀区金沙江路 1516 弄' },
      ],
      pagination: {
        currentPage: 1,
        pageSize: 2,
        total: 4,
      },
    }
  },
}
</script>
Copy after login

2. Edit or operate the content in the table

Sometimes, we need to perform some operations or edits in the table. The El-Table component provides a variety of ways to complete these operations:

  • slot Slot: Table columns can be inserted into the table so that the column content can be customized. The following is an editing example:
<template>
  <el-table :data="tableData">
    <el-table-column
      prop="date"
      label="日期"
      width="180"
    ></el-table-column>
    <el-table-column
      prop="name"
      label="姓名"
      width="180"
    ></el-table-column>
    <el-table-column
      label="操作">
      <template slot-scope="scope">
        <el-button size="mini" type="primary" @click="handleEdit(scope.$index, scope.row)">编辑</el-button>
      </template>
    </el-table-column>
  </el-table>
</template>

<script>
export default {
  data() {
    return {
      tableData: [
        { date: '2016-05-02', name: '王小虎' },
        { date: '2016-05-04', name: '王小虎' },
        { date: '2016-05-01', name: '王小虎' },
        { date: '2016-05-03', name: '王小虎' },
      ],
    }
  },
  methods: {
    handleEdit(index, row) {
      console.log(index, row)
    },
  }
}
</script>
Copy after login
  • Customized table expansion area: You can add a customized table expansion area to make the operation more intuitive and convenient. The following is an example of a custom table extension area:
<template>
  <el-table :data="tableData">
    <el-table-column
      prop="date"
      label="日期"
      width="180"
    ></el-table-column>
    <el-table-column
      prop="name"
      label="姓名"
      width="180"
    ></el-table-column>
    <el-table-column
      label="操作"
      width="180">
      <template slot-scope="scope">
        <el-button size="mini" type="primary" @click="handleEdit(scope.$index, scope.row)">编辑</el-button>
      </template>
      <template slot="append">
        <el-button size="mini" type="primary">全选</el-button>
        <el-button size="mini" type="danger">删除</el-button>
      </template>
    </el-table-column>
  </el-table>
</template>

<script>
export default {
  data() {
    return {
      tableData: [
        { date: '2016-05-02', name: '王小虎' },
        { date: '2016-05-04', name: '王小虎' },
        { date: '2016-05-01', name: '王小虎' },
        { date: '2016-05-03', name: '王小虎' },
      ],
    }
  },
  methods: {
    handleEdit(index, row) {
      console.log(index, row)
    },
  }
}
</script>
Copy after login

2. Vuetify

Vuetify is a powerful and beautiful Vue UI component library. Here are some tips for using Vuetify:

1. Using Vuetify’s Grid system

Vuetify’s Grid system allows us to easily create flexible layouts. The following is an example of a Grid system:

<template>
  <v-container fluid>
    <v-row>
      <v-col cols="12" md="6" lg="4">
        <v-card>
          <v-card-text>
            Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do
            eiusmod tempor incididunt ut labore et dolore magna aliqua.
          </v-card-text>
        </v-card>
      </v-col>
      <v-col cols="12" md="6" lg="4">
        <v-card>
          <v-card-text>
            Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do
            eiusmod tempor incididunt ut labore et dolore magna aliqua.
          </v-card-text>
        </v-card>
      </v-col>
      <v-col cols="12" md="6" lg="4">
        <v-card>
          <v-card-text>
            Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do
            eiusmod tempor incididunt ut labore et dolore magna aliqua.
          </v-card-text>
        </v-card>
      </v-col>
    </v-row>
  </v-container>
</template>
Copy after login

2. Using Vuetify's Form component

Vuetify provides many useful form components, such as input boxes, selection boxes, switches, etc. The following is an example of a Vuetify form component:

<template>
  <v-container fluid>
    <v-form>
      <v-text-field label="姓名" v-model="name"></v-text-field>
      <v-select label="性别" :items="genders" v-model="gender"></v-select>
      <v-checkbox label="同意协议" v-model="checked"></v-checkbox>
      <v-btn color="primary" :disabled="!validForm">提交</v-btn>
    </v-form>
  </v-container>
</template>

<script>
export default {
  data() {
    return {
      name: '',
      gender: '',
      genders: [
        '男性',
        '女性',
        '其他',
      ],
      checked: false,
    }
  },
  computed: {
    validForm() {
      return this.name && this.gender && this.checked
    },
  },
}
</script>
Copy after login

3. Ant Design Vue

Ant Design Vue is the Vue version of Ant Design, which provides multiple powerful components, such as buttons and forms. , selector, etc. Here are some tips for using Ant Design Vue:

1. Using Ant Design Vue’s button component

Ant Design Vue’s button component allows us to create beautiful buttons easily. The following is an example of an Ant Design Vue button component:

<template>
  <div>
    <a-button>默认按钮</a-button>
    <a-button type="primary">主要按钮</a-button>
    <a-button type="danger">危险按钮</a-button>
    <a-button shape="round">圆角按钮</a-button>
    <a-button icon="search">带图标的按钮</a-button>
  </div>
</template>
Copy after login

2. Using the form component of Ant Design Vue

Ant Design Vue provides multiple useful form components, such as input boxes, selections selector, date picker, etc. Here is an example of an Ant Design Vue form component:

<template>
  <div>
    <a-form>
      <a-form-item label="姓名">
        <a-input v-model="name"></a-input>
      </a-form-item>
      <a-form-item label="日期">
        <a-date-picker v-model="date"></a-date-picker>
      </a-form-item>
      <a-form-item label="城市">
        <a-select v-model="city">
          <a-select-option value="北京">北京</a-select-option>
          <a-select-option value="上海">上海</a-select-option>
          <a-select-option value="广州">广州</a-select-option>
        </a-select>
      </a-form-item>
      <a-button type="primary" :disabled="!validForm">提交</a-button>
    </a-form>
  </div>
</template>

<script>
export default {
  data() {
    return {
      name: '',
      date: '',
      city: '',
    }
  },
  computed: {
    validForm() {
      return this.name && this.date && this.city
    },
  },
}
</script>
Copy after login

Summary

Vue UI components allow us to build web applications faster and more efficiently. This article introduces commonly used Vue component libraries and provides some tips and practical skills. Trying these tips can help us better develop Vue applications and provide users with a better experience.

The above is the detailed content of Tips on using common Vue UI components. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template