14: element ui 使用
1.1 element ui 基本使用
参考网址: http://element.eleme.io/#/zh-CN/component/button
1、初始一个vue项目并安装element ui
vue init webpack-simple element-demo
cd element-demo
npm install
cnpm install element-ui -S
npm run dev
2、编辑main.js引入element ui (引入后就可以使用element中的样式了)
import Vue from 'vue'
import ElementUI from 'element-ui'; // 引入element-ui
import 'element-ui/lib/theme-chalk/index.css'; // element-ui的css样式要单独引入
import App from './App.vue' Vue.use(ElementUI); // 这种方式引入了ElementUI中所有的组件 new Vue({
el: '#app',
render: h => h(App)
})
main.js
3、在webpack.config.js中添加loader
var path = require('path')
var webpack = require('webpack')
module.exports = {
entry: './src/main.js',
output: {
path: path.resolve(__dirname, './dist'),
publicPath: '/dist/',
filename: 'build.js'
},
module: {
rules: [
{
test: /\.css$/,
use: [
'vue-style-loader',
'css-loader'
],
}, {
test: /\.vue$/,
loader: 'vue-loader',
options: {
loaders: {
}
// other vue-loader options go here
}
},
{
test: /\.js$/,
loader: 'babel-loader',
exclude: /node_modules/
},
{
test: /\.(png|jpg|gif|svg)$/,
loader: 'file-loader',
options: {
name: '[name].[ext]?[hash]'
}
},
// 添加加载字体字库的loader
{
test: /\.(eot|svg|ttf|woff|woff2)(\?\S*)?$/,
loader: 'file-loader'
},
]
},
resolve: {
alias: {
'vue$': 'vue/dist/vue.esm.js'
},
extensions: ['*', '.js', '.vue', '.json']
},
devServer: {
historyApiFallback: true,
noInfo: true,
overlay: true
},
performance: {
hints: false
},
devtool: '#eval-source-map'
}
if (process.env.NODE_ENV === 'production') {
module.exports.devtool = '#source-map'
// http://vue-loader.vuejs.org/en/workflow/production.html
module.exports.plugins = (module.exports.plugins || []).concat([
new webpack.DefinePlugin({
'process.env': {
NODE_ENV: '"production"'
}
}),
new webpack.optimize.UglifyJsPlugin({
sourceMap: true,
compress: {
warnings: false
}
}),
new webpack.LoaderOptionsPlugin({
minimize: true
})
])
}
webpack.config.js
4、在App.vue中使用element-ui
<template>
<div id="app">
{{msg}} <!--图标-->
<div>
<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-button type="primary" icon="el-icon-search">搜索</el-button>
</el-row>
</div> <!-- 日期选择器 -->
<DatePicker></DatePicker>
<!-- 文件上传 -->
<Upload></Upload>
</div>
</template> <script>
// 导入组件
import DatePicker from './components/DatePicker.vue'
import Upload from './components/Upload.vue' export default {
name: 'app',
data () {
return {
msg: '测试msg'
}
},
components:{
DatePicker,
Upload
}
}
</script> <style>
#app {
font-family: 'Avenir', Helvetica, Arial, sans-serif;
-webkit-font-smoothing: antialiased;
-moz-osx-font-smoothing: grayscale;
text-align: center;
color: #2c3e50;
margin-top: 60px;
} h1, h2 {
font-weight: normal;
} ul {
list-style-type: none;
padding: 0;
} li {
display: inline-block;
margin: 0 10px;
} a {
color: #42b983;
}
</style>
App.vue
5、在src中创建 components/DatePicker.vue 和 components/Upload.vue 两个组件
<template>
<el-date-picker
v-model="value"
type="date"
placeholder="选择日期"
size="small"
:picker-options="options">
</el-date-picker>
</template> <script>
export default {
data(){
return {
value:'',
options:{
disabledDate(time) {
return time.getTime() < Date.now() - 8.64e7;
},
firstDayOfWeek:1
}
}
}
}
</script>
DatePicker.vue
<template>
<el-upload
class="upload-demo"
action="https://jsonplaceholder.typicode.com/posts/"
:on-preview="handlePreview"
:on-remove="handleRemove"
:file-list="fileList">
<el-button size="small" type="primary">点击上传</el-button>
<div slot="tip" class="el-upload__tip">只能上传jpg/png文件,且不超过500kb</div>
</el-upload>
</template> <script>
export default {
data(){
return {
fileList: [
{
name: 'food.jpeg',
url: 'https://fuss10.elemecdn.com/3/63/4e7f3a15429bfda99bce42a18cdd1jpeg.jpeg?imageMogr2/thumbnail/360x360/format/webp/quality/100'
},
{
name: 'food2.jpeg',
url: 'https://fuss10.elemecdn.com/3/63/4e7f3a15429bfda99bce42a18cdd1jpeg.jpeg?imageMogr2/thumbnail/360x360/format/webp/quality/100'
}
]
}
},
methods: {
handleRemove(file, fileList) {
console.log(file, fileList);
},
handlePreview(file) {
console.log(file);
}
}
} </script>
Upload.vue

14: element ui 使用的更多相关文章
- vue+element ui项目总结点(一)select、Cascader级联选择器、encodeURI、decodeURI转码解码、mockjs用法、路由懒加载三种方式
不多说上代码: <template> <div class="hello"> <h1>{{ msg }}</h1> <p> ...
- 【Element UI】使用问题记录
[Element UI]使用问题记录 转载:https://www.cnblogs.com/yangchongxing/p/10750994.html 下载地址: https://unpkg.com/ ...
- vue-cli按需引入Element UI组件
一.环境 使用vue-cli搭建的环境 二.安装 babel-plugin-component npm install babel-plugin-component -D 三.修改.babelrc文件 ...
- 使用element ui 日期选择器获取值后的格式问题
一般情况下,我们需要给后台的时间格式是: "yyyy-MM-dd" 但是使用Element ui日期选择器获取的值是这样的: Fri Sep :: GMT+ (中国标准时间) 在官 ...
- element ui 1.4 升级到 2.0.11
公司的框架 选取的是 花裤衩大神开源的 基于 element ui + Vue 的后台管理项目, 项目源码就不公开了,记录 分享下 步骤 1. 卸载 element ui 1.4的依赖包 2. 卸载完 ...
- [坑况]饿了么你是这样的前端——vue+element ui 【this dependency was not found:'element-ui/lib/theme-chalk/index.css'】
element ui 坑况:今日pull代码,潇洒npm run dev ,被告知:this dependency was not found:'element-ui/lib/theme-chalk/ ...
- Vue + Element UI项目初始化
1.安装相关组件 1.1安装Node 检查本地是否安装node node -v 如果没有安装,从Node官网下载 1.2安装npm npm -v 如果没有安装:使用该指令安装: npm install ...
- Element UI——本地引入iconfont不显示
前言 前面因为本地引入Element UI导致了iconfont不显示,所以只好再去Element UI官网去扒下iconfot 步骤 进入官网 组件 | Element UI F12进入控制台,找到 ...
- Html | Vue | Element UI——引入使用
前言 做个项目,需要一个效果刚好Element UI有,就想配合Vue和Element UI,放在tp5.1下使用,但是引入在线的地址各种报错,本地引入就完美的解决了问题! 代码 __STATIC_J ...
随机推荐
- 胸片和CT断层图像是怎么来的?
本文作者系医科大学青年教师,关注公众号"计算机视觉life"菜单栏回复"医学" 进群交流 如何得到CT断层图像? 相信小伙伴体检的时候都拍过胸片,假如哪个不幸的 ...
- unity3d-游戏实战突出重围,第三天 绘制数字
实现效果: 准备资源 using UnityEngine; using System.Collections; public class hznum : MonoBehaviour { //存储图片资 ...
- mybatis--parametertype的参数传递
<?xml version="1.0" encoding="UTF-8" ?> <!DOCTYPE configuration PUBLIC ...
- sqlmap常用技巧整理
言 通过在乌云网上出现的很多SQL注入漏洞,因此来总结一下,大致使用SQLMAP所遇到的参数. 基本结构 基本SQLMAP的使用方式就如下所示,使用参数式的方式,按需求添加. 12 sqlmap.py ...
- mysqldump导出数据
如果导出的数据是乱码,需要制定--default-character-set= mysqldump -h wn-fala-v2-cluster.cluster-cczg3tb617nn.eu-cent ...
- mysql存储过程或函数中传入参数与表字段名相同引发的悲剧
真实案例.如下的一个存储过程: create procedure Apple(in user_id int) begin delete from users where user_id = user_ ...
- C语言---选择结构和循环结构
C语言的两种选择语句,1) if语句; 2) switch语句; 在if判断语句中,一般使用关系表达式. 关系运算符: <.<=.>.>=.==.!= 关系表达式:用关系运算符 ...
- yii2 modules模块配置指南
在Yii2 中模块是可以无限级嵌套的,也就是说,模块可以包含另一个包含模块的模块,我们称前者为父模块,后者为子模块, 子模块必须在父模块的yiibaseModule::modules属性中申明,例如: ...
- HDU1007.Quoit Design
-- 点我 -- 题目大意 :给你一堆点,求一个最小圆能够覆盖两个点的半径(最近两点距离的一半): 最多100000个点,暴力即O(n^2)会超时,考虑二分,先求左边最短距离dl,右边dr, 和一个点 ...
- Spark核心RDD:combineByKey函数详解
https://blog.csdn.net/jiangpeng59/article/details/52538254 为什么单独讲解combineByKey? 因为combineByKey是Spark ...