Home >Web Front-end >Front-end Q&A >How to use ele in vue

How to use ele in vue

WBOY
WBOYOriginal
2023-05-08 10:11:07619browse

Tutorial on using the Element UI framework in Vue

Vue is one of the most popular front-end frameworks at the moment, and Element UI is a set of component libraries based on Vue.js, which is a very popular one in Vue frame. This article will introduce how to use the Element UI framework in Vue.

1. Installation of Element UI

Before installing Element UI, you need to install Vue.js first. It is recommended to use the Vue.js scaffolding vue-cli. You can run the following command in the command line:

npm install -g vue-cli

After the installation is complete, you can create the Vue project through the following command:

vue init webpack my-project

After the creation is completed After that, enter the project directory and install the Element UI framework:

npm install element-ui --save

After the installation is completed, the Eleme UI framework can be introduced into the project.

2. Using Element UI in Vue

Introducing the Element UI framework into the project needs to be introduced in main.js and used using the Vue.use() method:

import Vue from 'vue'
import App from './App.vue'
import ElementUI from 'element-ui'
import 'element-ui/lib/theme-chalk/index.css'

Vue.use(ElementUI)
Vue.config.productionTip = false

new Vue({
  render: h => h(App),
}).$mount('#app')

It should be noted that the CSS file of Element UI needs to be introduced before introducing Element UI. In the above code, import 'element-ui/lib/theme-chalk/index.css' is used to introduce CSS files. You also need to use the components provided by Element UI in the template, for example:

<template>
  <div>
    <el-button type="primary">按钮</el-button>
  </div>
</template>

The Button component in Element UI is used here. More components can be used as needed. All components can be found in the official documentation of Element UI.

3. Use of Element UI components

  1. Button component

Use the Button component in Vue as follows:

<el-button>默认按钮</el-button>
<el-button type="primary">主要按钮</el-button>
<el-button type="success">成功按钮</el-button>
<el-button type="warning">警告按钮</el-button>
<el-button type="danger">危险按钮</el-button>
<el-button type="info">信息按钮</el-button>

Among them, The type attribute is the type of button.

  1. Input component

Use the Input component in Vue as follows:

<el-input v-model="inputValue" placeholder="请输入内容" style="width: 200px;"></el-input>

Among them, v-model is used for two-way binding data, and placeholder is used for Set the placeholder text for the Input.

  1. Radio component

Use the Radio component in Vue as follows:

<el-radio v-model="radio" label="1">备选项1</el-radio>
<el-radio v-model="radio" label="2">备选项2</el-radio>

Among them, v-model is used for two-way binding data, and label is used for Record the currently selected value.

  1. Checkbox component

Use the Checkbox component in Vue as follows:

<el-checkbox-group v-model="checkbox">
  <el-checkbox label="复选框 A"></el-checkbox>
  <el-checkbox label="复选框 B"></el-checkbox>
  <el-checkbox label="复选框 C"></el-checkbox>
  <el-checkbox label="禁用" disabled></el-checkbox>
  <el-checkbox label="选中且禁用" disabled></el-checkbox>
</el-checkbox-group>

Among them, el-checkbox-group is used to combine multiple Checkboxes Use it together, and use v-model to bind data in two directions. Each Checkbox component needs to set the label attribute to record the currently selected value.

  1. Select component

Use the Select component in Vue as follows:

<el-select v-model="value" placeholder="请选择">
  <el-option label="北京" value="Beijing"></el-option>
  <el-option label="上海" value="Shanghai"></el-option>
  <el-option label="广州" value="Guangzhou"></el-option>
  <el-option label="深圳" value="Shenzhen"></el-option>
</el-select>

Among them, v-model is used for two-way binding data, el-option Components are used to represent each option and its corresponding value.

The above is the basic content of the Element UI framework used in Vue. You can use more components and methods according to your specific needs. At the same time, you can also view more tutorials and documents on the official website of Element UI.

The above is the detailed content of How to use ele in vue. For more information, please follow other related articles on the PHP Chinese website!

Statement:
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
Previous article:How to transition in vueNext article:How to transition in vue