Vue中怎样引入Element
引入Element
完整引入
在vue项目下的src下的main.js中加入
import Vue from 'vue';
import ElementUI from 'element-ui';
import 'element-ui/lib/theme-chalk/index.css';
import App from './App.vue';Vue.use(ElementUI);new Vue({el: '#app',render: h => h(App)
});
这样就完成了Element的引入,样式文件需要单独引入。
按需引入
需要借助babel-plugin-component,我们可以只引入需要的组件。
安装babel-plugin-component:
在项目目录下打开cmd,然后输入:
npm install babel-plugin-component -D 或者 cnpm install babel-plugin-component -D
新建vue项目教程:
https://blog.csdn.net/BADAO_LIUMANG_QIZHI/article/details/83409981
然后在项目下搜索:.babelrc文件
将其修改为:
{"presets": [["es2015", { "modules": false }]],"plugins": [["component",{"libraryName": "element-ui","styleLibraryName": "theme-chalk"}]]
}
如果想引入部分组件,比如Button和Select,那么需要在main.js中写入
import Vue from 'vue';
import { Button, Select } from 'element-ui';
import App from './App.vue';Vue.component(Button.name, Button);
Vue.component(Select.name, Select);
/* 或写为* Vue.use(Button)* Vue.use(Select)*/new Vue({el: '#app',render: h => h(App)
});
完整的组件列表和引入方式:
import Vue from 'vue';
import {Pagination,Dialog,Autocomplete,Dropdown,DropdownMenu,DropdownItem,Menu,Submenu,MenuItem,MenuItemGroup,Input,InputNumber,Radio,RadioGroup,RadioButton,Checkbox,CheckboxButton,CheckboxGroup,Switch,Select,Option,OptionGroup,Button,ButtonGroup,Table,TableColumn,DatePicker,TimeSelect,TimePicker,Popover,Tooltip,Breadcrumb,BreadcrumbItem,Form,FormItem,Tabs,TabPane,Tag,Tree,Alert,Slider,Icon,Row,Col,Upload,Progress,Badge,Card,Rate,Steps,Step,Carousel,CarouselItem,Collapse,CollapseItem,Cascader,ColorPicker,Transfer,Container,Header,Aside,Main,Footer,Loading,MessageBox,Message,Notification
} from 'element-ui';Vue.use(Pagination);
Vue.use(Dialog);
Vue.use(Autocomplete);
Vue.use(Dropdown);
Vue.use(DropdownMenu);
Vue.use(DropdownItem);
Vue.use(Menu);
Vue.use(Submenu);
Vue.use(MenuItem);
Vue.use(MenuItemGroup);
Vue.use(Input);
Vue.use(InputNumber);
Vue.use(Radio);
Vue.use(RadioGroup);
Vue.use(RadioButton);
Vue.use(Checkbox);
Vue.use(CheckboxButton);
Vue.use(CheckboxGroup);
Vue.use(Switch);
Vue.use(Select);
Vue.use(Option);
Vue.use(OptionGroup);
Vue.use(Button);
Vue.use(ButtonGroup);
Vue.use(Table);
Vue.use(TableColumn);
Vue.use(DatePicker);
Vue.use(TimeSelect);
Vue.use(TimePicker);
Vue.use(Popover);
Vue.use(Tooltip);
Vue.use(Breadcrumb);
Vue.use(BreadcrumbItem);
Vue.use(Form);
Vue.use(FormItem);
Vue.use(Tabs);
Vue.use(TabPane);
Vue.use(Tag);
Vue.use(Tree);
Vue.use(Alert);
Vue.use(Slider);
Vue.use(Icon);
Vue.use(Row);
Vue.use(Col);
Vue.use(Upload);
Vue.use(Progress);
Vue.use(Badge);
Vue.use(Card);
Vue.use(Rate);
Vue.use(Steps);
Vue.use(Step);
Vue.use(Carousel);
Vue.use(CarouselItem);
Vue.use(Collapse);
Vue.use(CollapseItem);
Vue.use(Cascader);
Vue.use(ColorPicker);
Vue.use(Transfer);
Vue.use(Container);
Vue.use(Header);
Vue.use(Aside);
Vue.use(Main);
Vue.use(Footer);Vue.use(Loading.directive);Vue.prototype.$loading = Loading.service;
Vue.prototype.$msgbox = MessageBox;
Vue.prototype.$alert = MessageBox.alert;
Vue.prototype.$confirm = MessageBox.confirm;
Vue.prototype.$prompt = MessageBox.prompt;
Vue.prototype.$notify = Notification;
Vue.prototype.$message = Message;
全局配置
在引入 Element 时,可以传入一个全局配置对象。该对象目前支持 size 与 zIndex 字段。size 用于改变组件的默认尺寸,zIndex 设置弹框的初始 z-index(默认值:2000)。
完整引入 Element:
import Vue from 'vue';
import Element from 'element-ui';
Vue.use(Element, { size: 'small', zIndex: 3000 });
按需引入 Element:
import Vue from 'vue';
import { Button } from 'element-ui';Vue.prototype.$ELEMENT = { size: 'small', zIndex: 3000 };
Vue.use(Button);
按照以上设置,项目中所有拥有 size 属性的组件的默认尺寸均为 'small',弹框的初始 z-index 为 3000。
Vue中怎样引入Element相关推荐
- Vue中import引入模块路径时的@符号
Vue中import引入模块路径时的@符号 1.ES6 模块主要有两个功能:export 和 import export:用户对外输出本模块(一个文件可以理解为一个模块,比如 aaa.js bbb.j ...
- vue中如何引入指定字体并且使用
vue中如何引入指定字体并且使用 步骤一:在src下建立文件夹fonts fonts下引入字体文件且建立一个css文件 在css中定义字体样式 @font-face { font-family: '字 ...
- vue中图片引入问题以及实现openlayers地图标记
最近因为工作需要,在研究openlayers地图的使用,但是卡在了地图标记这块,不论我怎么尝试,标记就是不会显示在地图上,反反复复看了很多博客,也研究了文档,都觉得没有问题,也用html尝试了,标记可 ...
- vue中怎么引入字体包(超详细)
vue中怎么引入字体包 一.创建文件并添加字体包 1.在src里面的assets文件中创建text文件(没有assets文件可以自己创建一个,也可以不用此命名): 2.把字体包放入text文件,并创建 ...
- Vue中如何引入ElementUI
使用vue-cli创建好test项目后,将element-ui引入到项目中 使用npm 安装element-ui 跳转到test项目的根目录中 使用npm i element-ui -S进行安装 引入 ...
- 新建vue项目并引入element组件
从新建vue项目到引入组件Element 以及Error when rendering component报错解决 一.新建项目 1.打开cmd,运行:vue init webpack Vue-Dem ...
- vue中全局引入bootstrap.css
1.首先在官网上下载bootstrap的压缩包(必须是官网上下载的) 将压缩包解压后引入在项目文件夹下面.如下图所示: 2.在main.js中引入 import './assets/bootstrap ...
- vue中动态引入图片为什么要是require, 你不知道的那些事
相信用过vue的小伙伴,肯定被面试官问过这样一个问题:在vue中动态的引入图片为什么要使用require 有些小伙伴,可能会轻蔑一笑:呵,就这,因为动态添加src被当做静态资源处理了,没有进行编译,所 ...
- 在vue2.x项目中怎么引入Element UI
参考:https://blog.csdn.net/u014054437/article/details/79862793 Element使用方法:https://element.eleme.cn/#/ ...
最新文章
- 返回,返回无,根本没有返回?
- JS 怎样模拟类的特性
- (36)内核空间与内核模块,遍历内核模块链表
- linux挂载硬盘 只读,mount: /dev/vdb 写保护,将以只读方式挂载
- [Innost]Android深入浅出之Binder机制
- mysql: you can't specify target table 问题解决
- mysql —— 分表分区
- clipse中Access restriction: The type ‘XXX’ is not API 解决
- php怎么让视频自动播放,怎样让优酷等视频实现自动播放
- mysql数据库服务器实例_服务器上运行一个mysql实例里有多个数据库呢?还是多MYSQL实例?...
- android imagebutton 点击效果缩小,imagebutton 设置点击和按压效果
- 表单标签<input>的介绍
- 怎样在计算机上登录qq音乐,如何使用手机控制电脑qq音乐播放
- 我们编写的python代码在运行过程中_在 Rust 代码中编写 Python 是种怎样的体验?...
- H5 查看大图。缩放图片
- java大马后门_【猥琐流】制作一个隐藏在黑页下的大马并且添加后门
- 语音转文字转换器怎么用,免费的语音转文字方法介绍
- Google及Facebook第三方登录问题,“将你登入到此应用时出错,请稍后再试”
- 生物制药专业与计算机应用文献,生物制药技术专业求职信范文3篇
- thegraph subgraph 踩坑之入门青铜
热门文章
- BigDecimal的使用说明
- 快速排序法(思想及代码实现)
- 如何理解clone对象
- SpringBoot整合Minio 项目中使用自己文件存储服务器
- MySQL 条件查询 limit、in、between and、like等等
- 联想壁纸大赛——花卉与蝴蝶
- 进制转换应用场景_PLC编程:PLC内部各类型数据转换(整理分享)
- 以mips为单位衡量微型计算机的性能,2016计算机二级《MS Office》选择题专项训练...
- 名词用作动词举例_2020考研英语语法全面举例讲解:逻辑意义一致原则
- 关键信息基础设施保护条例_韩永刚:内生安全助力关键信息基础设施保护