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 使用的更多相关文章

  1. vue+element ui项目总结点(一)select、Cascader级联选择器、encodeURI、decodeURI转码解码、mockjs用法、路由懒加载三种方式

    不多说上代码: <template> <div class="hello"> <h1>{{ msg }}</h1> <p> ...

  2. 【Element UI】使用问题记录

    [Element UI]使用问题记录 转载:https://www.cnblogs.com/yangchongxing/p/10750994.html 下载地址: https://unpkg.com/ ...

  3. vue-cli按需引入Element UI组件

    一.环境 使用vue-cli搭建的环境 二.安装 babel-plugin-component npm install babel-plugin-component -D 三.修改.babelrc文件 ...

  4. 使用element ui 日期选择器获取值后的格式问题

    一般情况下,我们需要给后台的时间格式是: "yyyy-MM-dd" 但是使用Element ui日期选择器获取的值是这样的: Fri Sep :: GMT+ (中国标准时间) 在官 ...

  5. element ui 1.4 升级到 2.0.11

    公司的框架 选取的是 花裤衩大神开源的 基于 element ui + Vue 的后台管理项目, 项目源码就不公开了,记录 分享下 步骤 1. 卸载 element ui 1.4的依赖包 2. 卸载完 ...

  6. [坑况]饿了么你是这样的前端——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/ ...

  7. Vue + Element UI项目初始化

    1.安装相关组件 1.1安装Node 检查本地是否安装node node -v 如果没有安装,从Node官网下载 1.2安装npm npm -v 如果没有安装:使用该指令安装: npm install ...

  8. Element UI——本地引入iconfont不显示

    前言 前面因为本地引入Element UI导致了iconfont不显示,所以只好再去Element UI官网去扒下iconfot 步骤 进入官网 组件 | Element UI F12进入控制台,找到 ...

  9. Html | Vue | Element UI——引入使用

    前言 做个项目,需要一个效果刚好Element UI有,就想配合Vue和Element UI,放在tp5.1下使用,但是引入在线的地址各种报错,本地引入就完美的解决了问题! 代码 __STATIC_J ...

随机推荐

  1. php curl POST multipart/form-data与application/x-www-form-urlencode的区别

    背景 CURL在 a.php 中以 POST方式向 b.php 提交数据,但b.php无法接收到数据,而 CURL 操作显示成功. 原来,"传递一个数组到CURLOPT_POSTFIELDS ...

  2. 如何提取cocos iOS应用程序APP与游戏安装包里的资源与文件

    平时玩手机,看到iOS app中许多不错的图片素材的时候,有木有很心动,是不是想把其中的图片资源导出来使用,即可以练手,又可以提高自己的审美观0-0,增加app的颜值.当然,请不要作为商业用途.开发软 ...

  3. Lua 与 OC 相互调用

    本文主要讲如何完成lua和object-c的相互调用.       lua是一种脚本语言,可以方便的移植到各种宿主语言中,并且可以支持热更新,在游戏开发中也能当做主要的语言来编写游戏的逻辑,但是要接入 ...

  4. RNN的深入理解

    针对有着前后序列关系的数据,比如说随着时间变化的数据,显然使用rnn的效果会更好. 循环神经网络的简单结构如下图:简单表示是左边这幅图,展开来看就是右边对每个时刻的数据的处理.单层的RNN网络只有一个 ...

  5. Lepus(天兔)监控MySQL部署

    http://www.dbarun.com/docs/lepus/install/lnmp/ 注意:xampp mysqldb-python版本太高会导致lepus白屏 apache版本最好选择2.2 ...

  6. Ubuntu中使用pip3报错

    使用pip3 出现以下错误: Traceback (most recent call last): File “/usr/bin/pip3”, line 9, in from pip import m ...

  7. 使用sqoop往hdfs中导入数据供hive使用

    sqoop import -fs hdfs://x.x.x.x:8020 -jt local --connect "jdbc:oracle:thin:@x.x.x.x:1521:testdb ...

  8. linux中安装oracle数据库

    1. 执行 ./runInstaller 提示 /tmp 的空间过小执行 mount -o remount,size=1G,noatime /tmp重新设置 /tmp 的大小 2. 安装完成数据库之后 ...

  9. linux安装flash player来播放视频

    1下载64位flashplayer插件,可在此下载(偷偷赚俩金币,为省金币也可到官网去搜),得到flashplayer11_b2_install_lin_64_080811.tar.gz: http: ...

  10. python中的IO操作

    python中的基本IO操作: 1) 键盘输入函数:raw_input(string),不作处理的显示,与返回. input(string),可以接受一个python表达式作为返回,python内部得 ...