Element UI学习笔记

1.按钮点击弹出对话框

<!DOCTYPE html>
<html>
<head>
	<meta charset="utf-8">
	<title>Element UI Hello</title>
	<!-- 引用css -->
	<link rel="stylesheet" href="https://unpkg.com/element-ui/lib/theme-chalk/index.css">
	
 
</head>
<body>
	<div id="app">
		<el-row>
            <el-button>默认按钮</el-button>
            <el-button @click="open" 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>
		<el-dialog :visible.sync="visible" title="Hello World">
			<p>Try Element</p>
		</el-dialog>
	</div>
</body>
 
<script src="https://cdn.bootcdn.net/ajax/libs/vue/2.6.12/vue.min.js"></script>
<script src="https://cdn.bootcdn.net/ajax/libs/vue/2.6.12/vue.js"></script>
<script type="text/javascript" src="https://unpkg.com/element-ui/lib/index.js"></script>	
 
<script type="text/javascript">
	new Vue({
		el:'#app',
		data:function(){
			return {
				visible:false
			}
		},
        methods:{
            open(){
                this.visible=true
            }
        }
	})
</script>
 
</html>

 2.element ui全局引入

下载依赖

npm i element-ui -S

在以下 main.js 中写入内容:

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

Vue.config.productionTip = false
Vue.use(ElementUI)
/* eslint-disable no-new */
new Vue({
  el: '#app',
  router,
  components: { App },
  template: '<App/>'
})

 在新建的vue工程中找到Hello World.vue,加入element ui的组件

<template>
  <div class="hello">
    <el-button>按钮</el-button>
    <el-button type="primary">主要按钮</el-button>
  </div>
</template>

 3.element ui按需引入

使用 babel -plugin-component,我们可以只引入需要的组件,以实现项目体积的目的。

首先,安装 babel-plugin-component:

npm install babel-plugin-component -D

修改main.js

import Vue from 'vue'
import {Button} from 'element-ui'
import 'element-ui/lib/theme-chalk/index.css'
import App from './App'
import router from './router'

Vue.config.productionTip = false
Vue.use(Button)
/* eslint-disable no-new */
new Vue({
  el: '#app',
  router,
  components: { App },
  template: '<App/>'
})

 然后,将.babelrc修改为:

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

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值