คู่มือการติดตั้ง Element UI

คู่มือนี้ให้คำแนะนำอย่างละเอียดเกี่ยวกับวิธีการติดตั้งและใช้งาน Element UI ในโปรเจกต์ต่างๆ

ข้อกำหนดด้านสภาพแวดล้อม

Element UI มีข้อกำหนดดังนี้:

  • Vue 2.0.0+
  • Node.js 8.0.0+
  • เบราว์เซอร์สมัยใหม่ (Chrome, Firefox, Safari, Edge 10+)

วิธีการติดตั้ง

การใช้ตัวจัดการแพ็กเกจ

แนะนำให้ติดตั้งโดยใช้ npm:

npm install element-ui --save

หรือใช้ yarn:

yarn add element-ui

การนำเข้าแบบเต็ม

ใน main.js:

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

Vue.use(Element)

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

การนำเข้าแบบ on-demand

การนำเข้าแบบ on-demand สามารถลดขนาดโปรเจกต์ได้อย่างมาก

ขั้นแรกติดตั้ง babel-plugin-component:

npm install babel-plugin-component -D

จากนั้นตั้งค่าใน .babelrc:

{
  "presets": [["env", {
    "modules": false,
    "targets": {
      "browsers": ["> 1%", "last 2 versions", "not ie <= 8"]
    }
  }]],
  "plugins": [
    ["component", {
      "libraryName": "element-ui",
      "styleLibraryName": "theme-chalk"
    }]
  ]
}

นำเข้าคอมโพเนนต์ตามต้องการ:

import { Button, Select } from 'element-ui'

Vue.component(Button.name, Button)
Vue.component(Select.name, Select)

เทมเพลตเริ่มต้น

Element UI มีเทมเพลตโปรเจกต์อย่างเป็นทางการ:

การตั้งค่าแบบทั่วทั้งโปรเจกต์

เมื่อนำเข้า Element UI คุณสามารถส่งออบเจกต์การตั้งค่าแบบทั่วทั้งโปรเจกต์ได้:

import Vue from 'vue'
import Element from 'element-ui'

Vue.use(Element, {
  size: 'small',
  zIndex: 2000
})

ตัวเลือกการตั้งค่า:

  • size: ตั้งค่าขนาดเริ่มต้นสำหรับคอมโพเนนต์ฟอร์ม (medium / small / mini)
  • zIndex: ตั้งค่า z-index สำหรับคอมโพเนนต์ป็อปอัป ค่าเริ่มต้นคือ 2000

สำหรับข้อมูลเพิ่มเติม โปรดไปที่ เว็บไซต์ทางการของ Element UI