Install vue and import Element UI

First, enter in the terminal of the Vue project: npm i element-ui -S (after entering, press Enter, wait for a while, and the content below the red box in the figure below will appear, indicating that the installation has been successful)

Then, add in main.js:

import ElementUI from 'element-ui';
import 'element-ui/lib/theme-chalk/index.css';

Vue.use(ElementUI);

After completing the above steps, you can check whether it is installed: you can see the relevant information of Element UI in package.json

 Finally, you can test it. The following is the case on the official document:

<template>
  <el-form ref="form" :model="form" label-width="80px">
    <el-form-item label="event name">
      <el-input v-model="form.name"></el-input>
    </el-form-item>
    <el-form-item label="active area">
      <el-select v-model="form.region" placeholder="Please select the activity region">
        <el-option label="区域一" value="shanghai"></el-option>
        <el-option label="区域二" value="beijing"></el-option>
      </el-select>
    </el-form-item>
    <el-form-item label="Event Time">
      <el-col :span="11">
        <el-date-picker type="date" placeholder="选择日期" v-model="form.date1" style="width: 100%;"></el-date-picker>
      </el-col>
      <el-col class="line" :span="2">-</el-col>
      <el-col :span="11">
        <el-time-picker placeholder="选择时间" v-model="form.date2" style="width: 100%;"></el-time-picker>
      </el-col>
    </el-form-item>
    <el-form-item label="Instant delivery">
      <el-switch v-model="form.delivery"></el-switch>
    </el-form-item>
    <el-form-item label="Event Nature">
      <el-checkbox-group v-model="form.type">
        <el-checkbox label="Gourmet/restaurant online event" name="type"></el-checkbox>
        <el-checkbox label="Ground push activity" name="type"></el-checkbox>
        <el-checkbox label="offline activities" name="type"></el-checkbox>
        <el-checkbox label="Simple brand exposure" name="type"></el-checkbox>
      </el-checkbox-group>
    </el-form-item>
    <el-form-item label="Special Resources">
      <el-radio-group v-model="form.resource">
        <el-radio label="Online Brand Sponsorship"></el-radio>
        <el-radio label="Offline venues are free"></el-radio>
      </el-radio-group>
    </el-form-item>
    <el-form-item label="Event Form">
      <el-input type="textarea" v-model="form.desc"></el-input>
    </el-form-item>
    <el-form-item>
      <el-button type="primary" @click="onSubmit">Create now</el-button>
      <el-button>取消</el-button>
    </el-form-item>
  </el-form>

</template>

<script>
export default {
  data() {
    return {
      form: {
        name: '',
        region: '',
        date1: '',
        date2: '',
        delivery: false,
        type: [],
        resource: '',
        desc: ''
      }
    }
  },
  methods: {
    onSubmit() {
      console.log('submit!');
    }
  }
}

</script>

The following are the results of the operation:

 

おすすめ

転載: blog.csdn.net/m0_62404884/article/details/124010203