vue-12-element組件庫

1, 官網: 

http://element.eleme.io/#/zh-CNvue

2, 安裝

npm i element-ui -S

i : install,   -S  --save-dev 的簡寫npm

3, 使用 安需飲用的方式

npm install babel-plugin-component -D

 修改 .babelrc 文件element-ui

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

4, 在 main.js中引入須要的組件

// 引入 element
import { Button, Select } from 'element-ui';

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

5, 使用組件

 <el-row>
      <el-button>默認按鈕</el-button>
      <el-button type="primary">主要按鈕</el-button>
      <el-button type="success">成功按鈕</el-button>
      <el-button type="info">信息按鈕</el-button>
      <el-button type="warning">警告按鈕</el-button>
      <el-button type="danger">危險按鈕</el-button>
    </el-row>

 

更多樣式去官網查看babel

6, 輪播圖

添加 引入組件app

// 引入 element
import { Button, Select, Carousel, CarouselItem, } from 'element-ui';

Vue.component(Button.name, Button);
Vue.component(Select.name, Select);
/* 或寫爲
 * Vue.use(Button)
 * Vue.use(Select)
 */
Vue.use(Carousel)
Vue.use(CarouselItem)

 

templateui

<div>
      <el-carousel :interval="2000" type="card">
        <el-carousel-item v-for="(imgaa,index) in imgs" :key="item">
          <img :src="imgaa"/>
        </el-carousel-item>
      </el-carousel>
    </div>

定義dataspa

data() {
      return {
        msg: 'Welcome to Your Vue.js App',
        imgs: [
          "https://ss2.baidu.com/6ONYsjip0QIZ8tyhnq/it/u=2889938252,3793206744&fm=173&app=25&f=JPEG?w=639&h=424&s=A5D1AB66CC0937744EE54C120100C092",
          "https://ss2.baidu.com/6ONYsjip0QIZ8tyhnq/it/u=2889938252,3793206744&fm=173&app=25&f=JPEG?w=639&h=424&s=A5D1AB66CC0937744EE54C120100C092",
          "https://ss2.baidu.com/6ONYsjip0QIZ8tyhnq/it/u=2889938252,3793206744&fm=173&app=25&f=JPEG?w=639&h=424&s=A5D1AB66CC0937744EE54C120100C092",
          "https://ss2.baidu.com/6ONYsjip0QIZ8tyhnq/it/u=2889938252,3793206744&fm=173&app=25&f=JPEG?w=639&h=424&s=A5D1AB66CC0937744EE54C120100C092",
          "https://ss2.baidu.com/6ONYsjip0QIZ8tyhnq/it/u=2889938252,3793206744&fm=173&app=25&f=JPEG?w=639&h=424&s=A5D1AB66CC0937744EE54C120100C092",
          "https://ss2.baidu.com/6ONYsjip0QIZ8tyhnq/it/u=2889938252,3793206744&fm=173&app=25&f=JPEG?w=639&h=424&s=A5D1AB66CC0937744EE54C120100C092",
        ]
      }
    }
相關文章
相關標籤/搜索