一、iView(View UI)
一、iView(View UI)
1、简介
官网:https://www.iviewui.com/ 仓库:https://github.com/view-design/ViewUI iView 与 View UI 本质上是一个东西,随着版本的升级,iView (4.0)改名为 View UI。是一套基于Vue.js 的开源 UI 组件库。
2、安装、使用
(1)使用 npm 安装(项目中如何使用,命令行运行)
npm install view-design --save
使用 vue-cli3.0 创建项目,可以参考:https://www.cnblogs.com/l-y-h/p/11241503.html。
【小案例:在项目的 main.js 中引入】
【main.js】
import Vue from 'vue'
import App from './App.vue'
// step1: 引入 ViewUI
import ViewUI from 'view-design'
// step2: 引入 css
import 'view-design/dist/styles/iview.css'
Vue.config.productionTip = false
// step3:声明使用 ViewUI
Vue.use(ViewUI)
new Vue({
render: h => h(App),
}).$mount('#app')
【修改App.vue】
export default {
data() {
return {
visible: false
}
},
methods: {
show() {
this.visible = true
}
}
}
(2)不使用 npm 安装(单 html 中使用,直接运行)
【使用
【使用 标签引入 css 文件】
【小案例:(index.html)】
new Vue({
el: '#app',
data: {
visible: false
},
methods: {
show: function () {
this.visible = true
}
}
})
二、组件 -- 基础
1、颜色(Color)
详见: https://www.iviewui.com/components/color
2、字体(Font)
详见:https://www.iviewui.com/components/font
3、按钮(Button)
详见:https://www.iviewui.com/components/button
【App.vue】
通过 type 来设置不同样式的按钮
通过 ghost 可以将背景色置为透明,通常用于有色背景上
icon 可以设置图标、shape 可以设置按钮的图形,在 Button 内部使用 Icon 可以自定义图标的位置
Search
size 可以用来设置尺寸,large、default、small
long 可以用来填充宽度,宽度100%
loading 可以使按钮处于加载中的样式。disabled 使按钮不可用
使用 ButtonGroup 可以实现多个按钮组合的效果,shape 改变图形、size 改变大小、 vertical 使按钮组垂直显示
to 可以实现链接跳转,支持 vue-router 对象,replace 则不会向浏览器 history 中记录, target 等同于 a 标签
export default {
}
4、图标(Icon)
详见:https://www.iviewui.com/components/icon
【渲染前:】
【渲染后:】
三、组件 -- 布局
1、栅格系統(Grid)
详见:https://www.iviewui.com/components/grid
(1)使用栅格系统进行网页布局,可以使页面排版更加美观、舒适。
(2)采用 24 栅格系统。分为 row(行)和 col (列),其中 col 24 等分,可以使用 span 来控制。
【App.vue】
基本使用、水平布局
区块间隔, 使用 :gutter 可以设置区块间隔,Flex 可以改变 栅格顺序(与 order 连用)
push="x" 向右移 x 格, pull="x" 向左移 x 格, offset="x" 向右偏移 x 格
justify:flex 布局下的水平排列方式,可选值为start、end、center、space-around、space-between
子元素向左排列
子元素向右排列
子元素向居中排列
子元素等宽排列
子元素分散排列
align:flex 布局下的垂直对齐方式,可选值为top、middle、bottom
子元素顶部对齐
子元素居中对齐
子元素底部对齐
export default {}
2、布局(Layout)
详见:https://www.iviewui.com/components/layout
常用组件:Header、Sider、Content、Footer、 Layout
(1)Layout:布局容器,内部可嵌套 Header、Sider、Content、Footer、 Layout。可放在任意父容器中。
(2)Header:顶部布局,自带默认样式,只能放在 Layout 中。
(3)Sider:侧边栏布局,自带默认样式,只能放在 Layout 中。
(4)Content:内容主体布局,自带默认样式,只能放在 Layout 中。
(5)Footer:底部布局,自带默认样式,只能放在 Layout 中。
【App.vue】
Content
export default {
}
.layout{
border: 1px solid #d7dde4;
background: #f5f7f9;
position: relative;
border-radius: 4px;
overflow: hidden;
width: 800px;
}
.layout-logo{
width: 100px;
height: 30px;
background: #5b6270;
border-radius: 3px;
float: left;
position: relative;
top: 15px;
left: 20px;
}
.layout-nav{
width: 420px;
margin: 0 auto;
margin-right: 20px;
}
3、列表(List)
详见:https://www.iviewui.com/components/list
(1)基础的列表展示,可承载文字、列表、图片、段落,常用于后台数据展示页面。
(2)小案例分析
【App.vue】
一、使用 header 可以定义列表的头部, footer 可以定义列表的底部, size 可以定义列表的大小, border 定义列表的边界
Default Size:
Small Size:
Large Size:
二、ListItemMeta 中使用 avatar 可以定义图标, title 定义标题, description 定义内容
三、使用 item-layout="vertical" 可以使列表垂直
export default {
}
4、卡片(Card)
详见:https://www.iviewui.com/components/card
(1)基础容器,用来显示文字、列表、图文等内容,也可以配合其它组件一起使用。
(2)小案例分析:
【App.vue】
默认卡片效果
default
Content of card
Content of card
Content of card
不显示边框
bordered
Content of card
Content of card
Content of card
shadow显示卡片阴影
shadow
shadow存在时,dis-hover、bordered无效
禁用鼠标悬停显示阴影
dis-hover
Content of card
Content of card
Content of card
export default {
}
截图看的不明显,可以复制代码自行比较。
5、折叠面板(Collapse)
详见:https://www.iviewui.com/components/collapse
(1)可以显示、隐藏内容
(2)小案例分析
【App.vue】
一、v-model 绑定的是 当前索引值,指向选择的某个面板,与 Panel 的 name 相对应
Java
J A V A
Python
P Y T H O N
JavaScript
J A V A S C R I P T
二、accordion 只允许展开一个面板,面板可以嵌套
Java
J A V A
Python
P Y T H O N
JavaScript
Vue
V U E
Jquery
J Q U E R Y
React
R E A C T
export default {
data() {
return {
value1: '2',
value2: '1',
value3: '3'
}
}
}
6、面板切割、拖动效果(Split)
详见:https://www.iviewui.com/components/split
(1)可将一片区域,分割为可以拖拽调整宽度或高度的两部分区域。
(2)小案例分析:
【App.vue】
一、左右分割
Left Pane
Right Pane
二、上下分割
Top Pane
Bottom Pane
三、组合分割
Left Pane
Top Pane
Bottom Pane
Right Pane
export default {
data() {
return {
split1: 0.5,
split2: 0.3,
split3: 0.7,
split4: 0.4
}
},
}
.demo-split {
height: 250px;
border: 1px solid #dcdee2;
}
.demo-split2 {
height: 200px;
border: 1px solid #dcdee2;
}
.demo-split-pane {
padding: 10px;
}
7、分割线(Divider)
详见:https://www.iviewui.com/components/divider
(1)区分内容的分割线。
(2)小案例分析:
【App.vue】
一、type="vertical" 用于设置垂直分割线
Text
二、默认水平分割,orientation 可以设置分割标题的位置,dashed 可以设置分割线是否为虚线
System.out.println("Hello World")
Console.log("Hello World")
echo("Hello World")
export default {
}
8、单元格(Cell)
详见:https://www.iviewui.com/components/cell
(1)常用于菜单列表
(2)小案例分析
【App.vue】
title 只展示标题,label 展示内容, extra 在右侧展示内容, to用于跳转链接(默认图标)
export default {
data () {
return {
switchValue: true
}
},
}
四、组件 -- 导航
1、导航菜单(Menu)
详见:https://www.iviewui.com/components/menu
(1)为页面和功能提供导航的菜单列表,常用于网站顶部和左侧。
(2)小案例分析:
【App.vue】
一、通过 theme 属性可以设置菜单主题(primary只对水平菜单栏生效), mode="horizontal" 为水平菜单(默认为垂直菜单)
Change theme
二、使用 Submenu 可以定义二级菜单(可以嵌套),active-name 可以设置选中哪个 MenuItem, 使用 open-names 可以选择展开哪几个Submenu
三、使用 accordion 则每次只展开一个菜单, 使用 MenuGroup 可以进行菜单分组
export default {
data() {
return {
theme1: 'light'
}
}
}
2、标签页(Tabs)
详见:https://www.iviewui.com/components/tabs
(1)选项卡切换组件,常用于平级区域大块内容的的收纳和展现。
(2)小案例分析:
【App.vue】
一、使用label 可以定义标签内容,使用icon可以定义标签图标,使用 value 可以选中某个标签(与标签的name属性绑定,默认为选中第一个)
二、使用 disabled 可以禁用某个标签,使用 size 可以设置标签显示大小(只在 type="line"时生效)
三、type="card" 将标签显示为卡片样式, 通过 closable 、@on-tab-remove 可以进行删除标签的操作(注意若标签 存在 name 属性时,此时删除后,可能存在数据未清空的情况)
四、使用 slot="extra" 可以在标签右侧自定义内容, :animated 可以设置标签切换时是否有动画效果
export default {
data() {
return {
tab0: true,
tab1: true,
tab2: true,
tabs: 2
}
},
methods: {
handleTabRemove(name) {
this['tab' + name] = false;
},
handleTabsAdd() {
this.tabs++;
}
}
}
3、下拉菜单(Dropdown)
详见:https://www.iviewui.com/components/dropdown
(1)展示一组折叠的下拉菜单。用起来类似于 折叠面板(Collapse)
(2)小案例分析:
【App.vue】
一、下拉菜单基本使用,需 DropdownMenu、DropdownItem、 slot="list"结合。disabled 可以禁用某个菜单,divided 显示分割线
鼠标悬浮打开
二、使用 trigger 可以自定义展开方式(hover(默认,鼠标悬浮展开菜单),click 鼠标左键点击展开,contextMenu 鼠标右键展开,custom 自定义展开效果)
鼠标左键点击打开
鼠标右键点击打开
自定义事件展开
三、下拉菜单可以嵌套,使用 placement 可以设置菜单展开的方向
下拉菜单嵌套
设置菜单展开方向
export default {
data() {
return {
visible: false
}
}
}
4、分页(Page)
详见:https://www.iviewui.com/components/page
(1)当数据量较多时,使用分页可以快速进行数据切换。
(2)小案例分析:
【App.vue】
一、total 定义数据的总数,(page-size默认为10,即页面上10条数据为1页)
二、show-sizer 可用于切换每页显示的数量, 可以使用 @on-page-size-change 去返回切换后的值
三、show-elevator 可用于跳转到某一页, 可以使用 @on-change 去返回切换后的页码
四、show-total 可用于显示总条数, size 用于设置分页的大小
五、prev-text、next-text可用于替代两边的图标
export default {
methods: {
showPageSize (index) {
alert(index)
},
showPage (index) {
alert(index)
}
}
}
5、面包屑(Breadcrumb )
详见:https://www.iviewui.com/components/breadcrumb
(1)显示网站的层级结构,告知用户当前所在位置,以及在需要向上级导航时使用。
(2)小案例分析:
【App.vue】
一、默认以 '/' 分割
二、自定义分割线
export default {
}
.demo-breadcrumb-separator {
color: #ff5500;
padding: 0 5px;
}
6、步骤条(Steps)
详见:https://www.iviewui.com/components/steps
(1)拆分某项流程的步骤,引导用户按流程完成任务。
(2)小案例分析
【App.vue】
一、根据current 自动判断各个步骤的状态(从 0 开始计数)
二、size 可以设置大小
三、icon 可以设置图标, status 可以设置执行某步骤的状态(wait、process、finish、error)
四、direction 可以设置为垂直的步骤条
当前正在进行第 {{ current + 1 }} 步
export default {
data () {
return {
current: 0
}
},
methods: {
next () {
if (this.current === 3) {
this.current = 0
} else {
this.current++
}
}
}
}
.demo-badge {
width: 42px;
height: 42px;
background: #eee;
border-radius: 6px;
display: inline-block;
}
五、表单
1、输入框(Input)
详见:https://www.iviewui.com/components/input
(1)基本表单组件,支持 input 和 textarea,并在原生控件基础上进行了功能扩展,可以组合使用。
(2)小案例分析
【App.vue】
一、可以使用 v-model 实现双向绑定, placeholder 可以定义提示内容, size 可以设置输入框大小
二、使用 clearable 可以在输入框中显示清除按钮(输入框有值时). maxlength、show-word-limit 可以用于提示限制字符输入(会影响clearable)
三、使用密码框(type="password" password 可以隐藏、显示密码).
使用 icon 可以定义图标,点击图标可以触发 on-click 事件.
使用 search 可以设置搜索框样式, 可以结合 enter-button 使搜索图标变成 按钮的形式
四、可以通过 prefix 和 suffix 设置图标位置,直接使用 或者 使用slot同名引用
Props:
Slots:
五、可以使用 slot 引用 prepend, append 来设置前后样式
http://
.com
export default {
data() {
return {
value: 'HelloWorld'
}
},
methods: {
iconClick() {
alert("hello")
}
}
}
.demo-badge {
width: 42px;
height: 42px;
background: #eee;
border-radius: 6px;
display: inline-block;
}
2、开关(Switch)
详见:https://www.iviewui.com/components/switch(1)在两种状态间切换时用到的开关选择器。
(2)小案例分析:
【App.vue】
一、基本用法,状态切换时会触发事件(@on-change)。
使用 v-model 双向绑定数据。
设置属性 before-change 并返回 Promise,可以阻止切换。
使用 size 可以设置开关的大小
使用 slot 可以自定义文字
使用 disabled 可以禁用某个开关
使用 loading 可以出现加载中的样式
使用 true-color 和 false-color 可以设置开关样式
开启
关闭
export default {
data() {
return {
switch1: false,
switch2: false,
switch3: true
}
},
methods: {
change(status) {
this.$Message.info('开关状态:' + status)
},
handleBeforeChange() {
return new Promise((resolve) => {
this.$Modal.confirm({
title: '切换确认',
content: '您确认要切换开关状态吗?',
onOk: () => {
resolve()
}
})
})
}
}
}
3、表格(Table)
详见:https://www.iviewui.com/components/table(1)主要用于展示大量结构化数据。支持排序、筛选、分页、自定义操作、导出 csv 等复杂功能。(2)小案例分析:
【App.vue】
一、基本用法,columns 定义表格的列,data 定义表格每行数据。
stripe 定义斑马纹(表格会间隔显示不同颜色,用于区分不同行数据。
border 定义表格的边框.
highlight-row 可以选中某条数据,调用 clearCurrentRow 方法可以清除选中的数据.
@on-current-change 可以返回上一条与当前选择的数据。
在 column 中可以定义一列,并定义 type="index",用于自动生成序号。
在 column 中可以定义一列,并定义 type="selection",用于自动生成多选框。通过 selectAll 可以设置全选、取消全选
二、自定义模板
在 columns 的某列声明 slot 后,就可以在 Table 的 slot 中使用 slot-scope。
slot-scope 的参数有 3 个:当前行数据 row,当前列数据 column,当前行序号 index。
通过设置属性 loading 可以让表格处于加载中状态,在异步请求数据、分页时建议使用。
Change Loading Status
export default {
data() {
return {
loading: false,
column: true,
columns1: [{
type: 'index',
width: 80,
align: 'center'
}, {
title: 'Name',
key: 'name'
},
{
title: 'Age',
key: 'age'
},
{
title: 'Address',
key: 'address'
}, {
title: 'Date',
key: 'date'
}
],
columns2: [{
type: 'selection',
width: 80,
align: 'center'
}, {
title: 'Name',
key: 'name'
},
{
title: 'Age',
key: 'age'
},
{
title: 'Address',
key: 'address'
}, {
title: 'Date',
key: 'date'
}
],
columns3: [{
type: 'index',
width: 80,
align: 'center'
}, {
title: 'Name',
slot: 'name'
},
{
title: 'Age',
key: 'age'
},
{
title: 'Address',
key: 'address'
}, {
title: 'Date',
key: 'date'
},
{
title: 'Action',
slot: 'action',
width: 150,
align: 'center'
}
],
data1: [{
name: 'John Brown',
age: 18,
address: 'New York No. 1 Lake Park',
date: '2016-10-03'
},
{
name: 'Jim Green',
age: 24,
address: 'London No. 1 Lake Park',
date: '2016-10-01'
},
{
name: 'Joe Black',
age: 30,
address: 'Sydney No. 1 Lake Park',
date: '2016-10-02'
},
{
name: 'Jon Snow',
age: 26,
address: 'Ottawa No. 2 Lake Park',
date: '2016-10-04'
}
]
}
},
methods: {
handleClearCurrentRow() {
this.column = false
this.$refs.currentRowTable.clearCurrentRow();
},
handleSelectAll(status) {
this.column = false
this.$refs.currentRowTable.selectAll(status);
},
changeData(currentRow, oldCurrentRow) {
console.log(oldCurrentRow)
console.log(currentRow)
},
showIndex() {
this.column = true
},
showCheckBox() {
this.column = false
},
show(index) {
this.$Modal.info({
title: 'User Info',
content: `Name:${this.data1[index].name}
Age:${this.data1[index].age}
Address:${this.data1[index].address}`
})
},
remove(index) {
this.data1.splice(index, 1);
}
}
}
(3)表格实用小案例(表格 + 分页): 自定义模板、可以分页、分页后索引值可以跟着修改。
【App.vue】
Display border
Display stripe
Display index
Display multi choice
Display header
Table scrolling
Table size
export default {
data() {
return {
// 当前页码
currentPage: 1,
// 每页数据的条数
pageSize: 10,
// 表格的列
tableColumns1: [{
// 分页时,若要出现自动索引,设置type = "index2",并使用 render 来返回索引值
type: 'index2',
width: 80,
align: 'center',
render: (h, params) => {
return h('span', params.index + (this.currentPage - 1) * this.pageSize + 1);
}
},{
title: 'Name',
slot: 'name'
},
{
title: 'Age',
key: 'age',
sortable: true
},
{
title: 'Address',
key: 'address'
}, {
title: 'Date',
key: 'date',
sortable: true
},
{
title: 'Action',
slot: 'action',
width: 150,
align: 'center'
}
],
// 表格的源数据
data1: [{
name: 'John Brown',
age: 18,
address: 'New York No. 1 Lake Park',
date: '2016-10-03'
},
{
name: 'Jim Green',
age: 24,
address: 'London No. 1 Lake Park',
date: '2016-10-01'
},
{
name: 'Joe Black',
age: 30,
address: 'Sydney No. 1 Lake Park',
date: '2016-10-02'
},
{
name: 'Jon Snow',
age: 26,
address: 'Ottawa No. 2 Lake Park',
date: '2016-10-04'
}, {
name: 'John Brown',
age: 18,
address: 'New York No. 1 Lake Park',
date: '2016-10-03'
},
{
name: 'Jim Green',
age: 24,
address: 'London No. 1 Lake Park',
date: '2016-10-01'
},
{
name: 'Joe Black',
age: 30,
address: 'Sydney No. 1 Lake Park',
date: '2016-10-02'
},
{
name: 'Jon Snow',
age: 26,
address: 'Ottawa No. 2 Lake Park',
date: '2016-10-04'
},
{
name: 'Jim Green',
age: 24,
address: 'London No. 1 Lake Park',
date: '2016-10-01'
},
{
name: 'Joe Black',
age: 30,
address: 'Sydney No. 1 Lake Park',
date: '2016-10-02'
},
{
name: 'Jon Snow',
age: 26,
address: 'Ottawa No. 2 Lake Park',
date: '2016-10-04'
}
],
// 表格每页的数据
data2: [],
// 表格边框是否显示
showBorder: false,
// 表格斑马纹是否显示
showStripe: false,
// 表格头是否显示
showHeader: true,
// 表格索引是否显示
showIndex: true,
// 表格多选框是否显示
showCheckbox: false,
// 表格滚动条是否开启
fixedHeader: false,
// 改变表格大小
tableSize: 'default'
}
},
methods: {
changePage(index) {
// 改变当前的页码,并获取当前页码所拥有的数据
this.currentPage = index
this.data2 = this.data1.slice((index - 1) * this.pageSize, index * this.pageSize);
},
show(index) {
// 弹出一个模态框,用于展示某条数据的信息(``是ES6的模板字符串)
this.$Modal.info({
title: 'User Info',
content: `Name:${this.data2[index].name}
Age:${this.data2[index].age}
Address:${this.data2[index].address}`
})
},
remove(index) {
// 删除某条数据(删除源数据)
this.data1.splice((this.currentPage-1) * 10 + index, 1)
}
},
watch: {
showIndex(newVal) {
if (newVal) {
// 为true时,在首部增加一个索引列
this.tableColumns1.unshift({
// 分页时,若要出现自动索引,设置type = "index2",并使用 render 来返回索引值
type: 'index2',
width: 80,
align: 'center',
render: (h, params) => {
return h('span', params.index + (this.currentPage - 1) * this.pageSize + 1);
}
})
} else {
// 为false时,若首部存在索引列,则移除该列
this.tableColumns1.forEach((item, index) => {
if (item.type === 'index2') {
this.tableColumns1.splice(index, 1)
}
})
}
},
showCheckbox(newVal) {
if (newVal) {
// 为 true 时,在首部增加一多选框列,
this.tableColumns1.unshift({
type: 'selection',
width: 60,
align: 'center'
})
} else {
// 为false时,若存在多选框列,则移除该列
this.tableColumns1.forEach((item, index) => {
if (item.type === 'selection') {
this.tableColumns1.splice(index, 1)
}
})
}
},
data1() {
// 当列表数据改变时(比如删除某数据),触发一次刷新列表的操作
this.changePage(this.currentPage)
}
},
mounted() {
// 页面加载时,触发第一次刷新列表的操作
this.changePage(this.currentPage)
}
}
六、视图
1、警告提示(Alert)
详见:https://www.iviewui.com/components/alert(1)静态地呈现一些警告信息,可手动关闭。
(2)小案例分析:
【App.vue】
一、使用 type 可以定义警告框的类型(默认为 info)。
使用 slot="desc" 可以添加自定义内容。
使用 show-icon 可以显示图标(使用 slot="icon" 可以自定义图标)。
使用 closable 可以关闭警告框(可使用 on-close 监控关闭事件)
An error prompt
export default {
methods: {
close() {
alert("Hello")
}
}
}
2、全局提示(Message)
详见:https://www.iviewui.com/components/message(1)轻量级的信息反馈组件,在顶部居中显示,并自动消失。有多种不同的提示状态可选择。
(2)小案例分析:
【App.vue】
一、基本提示,默认在1.5秒后消失。可以提示不同的状态(不同颜色)。
二、可以设置背景色(background).
三、可以设置加载中样式,并定时取消(loading)。
可以设置关闭样式,主动关闭(closable)
export default {
methods: {
info() {
this.$Message.info('This is a info tip')
},
success() {
this.$Message.success('This is a success tip')
},
warning() {
this.$Message.warning('This is a warning tip')
},
error() {
this.$Message.error('This is an error tip')
},
background(type) {
this.$Message[type]({
background: true,
content: 'This is a ' + type + ' tip'
})
},
loading() {
// 两种延时关闭方法
// 第一种,使用定时器关闭(毫秒为单位)
// const msg = this.$Message.loading({
// content: 'Loading...',
// duration: 0
// })
// setTimeout(msg, 1000)
// 第二种,自定义关闭时间(秒为单位)
const msg = this.$Message.loading({
content: 'Loading...',
duration: 1
})
},
closable() {
this.$Message.info({
content: 'Tips for manual closing',
duration: 10,
closable: true
})
}
}
}
3、通知提醒(Notice)
详见:https://www.iviewui.com/components/notice(1)在界面右上角显示可关闭的全局通知,常用于:系统主动推送、通知内容带有描述信息。
(2)小案例分析:
【App.vue】
一、基本用法,默认在 4.5秒后关闭。如果 desc 参数为空或不填,则自动应用仅标题模式下的样式。
二、可以设置不同的类型(带图标、不带图标)。可以使用 duration 定时(为0时则为不定时)
export default {
methods: {
open(nodesc) {
this.$Notice.open({
title: 'Notification title',
desc: nodesc ? '' : 'Here is the notification description. Here is the notification description. '
})
},
info(nodesc) {
this.$Notice.info({
title: 'Notification title',
desc: nodesc ? '' : 'Here is the notification description. Here is the notification description. '
})
},
success(nodesc) {
this.$Notice.success({
title: 'Notification title',
desc: nodesc ? '' : 'Here is the notification description. Here is the notification description. '
})
},
warning(nodesc) {
this.$Notice.warning({
title: 'Notification title',
desc: nodesc ? '' : 'Here is the notification description. Here is the notification description. '
})
},
error(nodesc) {
this.$Notice.error({
title: 'Notification title',
desc: nodesc ? '' : 'Here is the notification description. Here is the notification description. '
})
},
time() {
this.$Notice.open({
title: 'Notification title',
desc: 'This notification does not automatically close, and you need to click the close button to close.',
duration: 1
})
}
}
}
4、抽屉(Drawer)
详见:https://www.iviewui.com/components/drawer(1)抽屉从父窗体边缘滑入,覆盖住部分父窗体内容。用户在抽屉内操作时不必离开当前任务,操作完成后,可以平滑地回到到原任务。
(2)小案例分析:
【App.vue】
一、基础抽屉,点击触发按钮抽屉从右滑出,点击遮罩区关闭(mask-closable 为false时,点击遮罩区不可关闭)。
Some contents...
Some contents...
Some contents...
二、使用 placement 可以设置抽屉出现的位置。当 closable = true 时,可以在右上角显示关闭按钮.
mask 为 false 时,不显示遮罩层.
Some contents...
Some contents...
Some contents...
export default {
data() {
return {
value1: false,
value2: false
}
}
}
5、对话框(Modal)
详见:https://www.iviewui.com/components/modal(1)模态对话框,在浮层中显示,引导用户进行相关操作。
(2)小案例分析
【App.vue】
一、基本用法。使用 v-model 可以双向绑定。on-ok、on-cancel 可以监听确定与关闭事件。按ESC相当于触发 on-cancel事件
Content of dialog
Content of dialog
Content of dialog
二、添加 loading 样式(:loading="true")。
使用 closable = "false" 可以禁用右上角关闭按钮。
使用 :mask-closable="false" 可以禁用 点击遮罩层关闭
使用 draggable 可以使对话框拖动,此时会主动关闭遮罩层
After you click ok, the dialog box will close in 2 seconds.
三、可以直接调用封装好的实例方法
export default {
data() {
return {
modal1: false,
modal2: false,
loading: true
}
},
methods: {
ok() {
this.$Message.info('Clicked ok');
},
cancel() {
this.$Message.info('Clicked cancel');
},
asyncOK() {
setTimeout(() => {
this.modal2 = false;
}, 2000);
},
instance(type) {
const title = 'Title';
const content = '
Content of dialog
Content of dialog
';switch (type) {
case 'info':
this.$Modal.info({
title: title,
content: content
})
break
case 'success':
this.$Modal.success({
title: title,
content: content
})
break
case 'warning':
this.$Modal.warning({
title: title,
content: content
})
break
case 'error':
this.$Modal.error({
title: title,
content: content
})
break
case 'confirm':
this.$Modal.confirm({
title: 'Title',
content: '
Content of dialog
Content of dialog
',onOk: () => {
this.$Message.info('Clicked ok')
},
onCancel: () => {
this.$Message.info('Clicked cancel')
},
okText: 'OK',
cancelText: 'Cancel'
})
}
}
}
}
未完待续。。。