80种奇奇怪怪的按钮,先睹为快!

本文详细讲解 View UI 中,Button 组件的样式配置和单击事件响应。


目录

一、按钮样式

1.1 颜色

1.2 大小

1.3 按钮形状

1.4 背景透明

1.5 按钮图标

1.6 其他样式

二、 按钮事件

2.1 按钮传值

2.1.1 无传输值单击事件

2.1.2 传输静态参数

2.1.3 传递动态参数

2.1.4 循环渲染传参

2.2 按钮跳转


如果你还没配置好 View UI 的开发环境,赶紧点击这里查看教程啦!


一、按钮样式

1.1 颜色

颜色是按钮的基础样式之一,通过设置Button 的 type属性,可以实现按钮颜色的变化

目前View UI支持以下八种颜色,分别为:

primary、dashed、text、info、success、warning、error

分别对应下图八种颜色

配置方法很简单,就是给 Button 组件,加一个 type 属性即可

<Button type="error">测试按钮</Button>

1.2 大小

大小也是按钮的基础样式之一,通过设置Button 的 size 属性,可以实现按钮大小的变化

目前View UI支持以下三种大小,分别为:

small、default、large

配置代码如下所示:

<Row :gutter="32"><Col span="2"><Button type="warning" size="small">测试按钮</Button></Col><Col span="2"><Button type="warning" size="default">测试按钮</Button></Col><Col span="2"><Button type="warning" size="large">测试按钮</Button></Col>
</Row>

1.3 按钮形状

圆角决定了这个按钮的四个边缘是否光滑。

在实际开发中,通常会设置圆角,让界面更有美感。

目前View UI只支持圆角这一种形状

通过设置 Button 组件的 shape 属性,实现圆角。

<Col span="2"><Button type="info" shape="circle">按钮25</Button>
</Col>

1.4 背景透明

背景透明在 View UI 中又称为 幽灵属性。

下图设置了背景透明,可以透过按钮看到淡蓝色的背景。

通过设置 Button 组件的 ghost 属性 = true,实现背景透明。

<Col span="2"><Button type="dashed" ghost>按钮13</Button>
</Col>

1.5 按钮图标

按钮的文字前面或后面可以放置图标,从而让按钮的功能更加通俗易懂。

View UI 自带了很多ICON图标,一般情况下可以满足我们的开发需求。

可以使用 Button 组件的 icon属性,为按钮设置前置图标

也可以通过在 Button 组件内,放置 Icon 组件,来实现按钮的前置、后置图标,但优先级小于 Button 组件配置的icon属性

演示效果如下所示:

源代码如下所示:

<Row :gutter="32"><Col span="2"><Button type="warning" shape="circle" icon="ios-wifi">测试按钮</Button></Col><Col span="2"><Button type="warning" shape="circle">测试按钮<Icon type="ios-add-circle-outline" /></Button></Col><Col span="2"><Button type="warning" shape="circle"><Icon type="ios-add-circle-outline" />测试按钮</Button></Col><Col span="2"><Button type="warning" shape="circle" icon="ios-wifi"><Icon type="ios-add-circle-outline" />测试按钮</Button></Col>
</Row>

1.6 其他样式

View UI 还支持其他的样式配置,因为不太常用,所以不再一一演示。

比如:

long 属性项,用于配置按钮宽度是否扩充至全屏

disabled 属性项,用于配置按钮是否被禁用,即无法被点击的样式

loading属性项,用于配置按钮是否显示加载中图标

html-type 属性项,用于兼容原生H5的提交属性

......


本文作者:郑为中

CSDN原文地址: https://zwz99.blog.csdn.net/article/details/115720476


二、 按钮事件

2.1 按钮传值

按钮,顾名思义就是按了之后能够扭动起来(就是能干事)。

我认为按钮在前端的作用,就是让C端用户主动去触发某个事件,完成人机交互。

其中很重要的一点,就是按钮点击传值问题,View UI 的按钮能不能传值? 方不方便?

答案当然是 —— 能!

View UI 的 Button 组件 可通过 @click 配置该按钮的单击事件

我分为四种情况,逐一测试

2.1.1 无传输值单击事件

按钮的单击事件,如果没有传参数,View UI 的 Button 组件会返回一个窗体对象,密密麻麻,包括点击的坐标值,屏幕宽高等等......

其实......这些东西对你来说,一点都没用。

对,你没听错! 一点都没用!一点都没用!一点都没用!

那么则么让他有用起来呢?就需要传值!

<Col span="6"><Button type="warning"  shape="circle" @click="clickTest">无传输值</Button>
</Col>

2.1.2 传输静态参数

在实际开发中,可能会遇到按钮需要传参的需求。

有一些的按钮是固定的,你点了他,就代表XXX的固定功能,那么可以考虑静态传参

<Col span="6"><Button type="warning"  shape="circle" @click="clickTest(3.14159)">传输数字</Button>
</Col>

传递参数后,在单击事件中打印即可,效果如下图所示:

2.1.3 传递动态参数

很多情况下,需要根据实际情况传递动态的参数值。

<Col span="6"><Button type="warning"  shape="circle" @click="clickTest(testData)">传输动态内容</Button>
</Col>

比如这个testData,是我自己定义的一个变量。

<script>
export default {name: 'test',data() {return {testData: '传输值'}},methods: {clickTest(e) {console.log(e);}}
}
</script>

这样就可以实现 Button 组件的动态传参。

2.1.4 循环渲染传参

我在实际开发中,用的最多的就是 v-for 下按钮传值

比如下面这样

<Row :gutter="32"><Col span="6" v-for="(item,index) in userList" :key="index"><Button type="warning"  shape="circle" @click="clickTest(item)">循环渲染传值{{index}}</Button></Col>
</Row>

userList 一般为后端传递过来的对象数组

我们需要给按钮的单击事件,传递数组中当前对象的,一个或多个属性值

<script>
export default {name: 'test',data() {return {testData: '传输值',userList: [{id: 1,name: 'ZWZ1'},{id: 2,name: 'ZWZ2'},{id: 3,name: 'ZWZ3'}]}},methods: {clickTest(e) {console.log(e);}}
}
</script>

这样就可以给按钮单击事件,传递相应的值

2.2 按钮跳转

有时会需要单击按钮打开某个网址

比如C端用户单击按钮后,导出Excel(对接Java POI),就要访问后端 API 的 URL,实现快速导出Excel。

当然可以使用 JS 自带的方法来打开网址

test() {window.open("https://blog.csdn.net/qq_41464123","_blank");
},

View UI 也为我们提供了快速跳转 URL 的方法,在 button 组件中,配置 to 属性即可。

View UI 还可以实现无痕浏览,满足开发者的多维需求。

<Row :gutter="32"><Col span="6"><Button to="https://blog.csdn.net/qq_41464123" type="warning"  shape="circle">我的博客</Button></Col><Col span="6"><Button to="https://blog.csdn.net/qq_41464123" type="warning"  shape="circle" replace>无痕浏览</Button></Col><Col span="6"><Button to="https://blog.csdn.net/qq_41464123" type="warning"  shape="circle" target="_blank">新标签访问</Button></Col>
</Row>

以上就是 View UI 的 Button 组件 常用的功能配置。


附:事件完整代码

<template><div class="hello"><Divider> ZWZ普通传值 </Divider><Row :gutter="32"><Col span="6"><Button type="warning"  shape="circle" @click="clickTest">无传输值</Button></Col><Col span="6"><Button type="warning"  shape="circle" @click="clickTest(3.14159)">传输数字</Button></Col><Col span="6"><Button type="warning"  shape="circle" @click="clickTest(testData)">传输动态内容</Button></Col></Row><Divider> ZWZ循环渲染 </Divider><Row :gutter="32"><Col span="6" v-for="(item,index) in userList" :key="index"><Button type="warning"  shape="circle" @click="clickTest(item)">循环渲染传值{{index}}</Button></Col></Row><Divider> ZWZ测试结束 </Divider></div>
</template><script>
export default {name: 'test',data() {return {testData: '传输值',userList: [{id: 1,name: 'ZWZ1'},{id: 2,name: 'ZWZ2'},{id: 3,name: 'ZWZ3'}]}},methods: {clickTest(e) {console.log(e);}}
}
</script><style scoped>
.hello {background-color: rgb(224, 249, 250);
}
</style>

附:样式完整Vue代码

<template><div class="hello"><Divider> 基础按钮 </Divider><Row :gutter="32"><Col span="2"><Button>按钮01</Button></Col><Col span="2"><Button type="primary">按钮02</Button></Col><Col span="2"><Button type="dashed">按钮03</Button></Col><Col span="2"><Button type="text">按钮04</Button></Col><Col span="2"><Button type="info">按钮05</Button></Col><Col span="2"><Button type="success">按钮06</Button></Col><Col span="2"><Button type="warning">按钮07</Button></Col><Col span="2"><Button type="error">按钮08</Button></Col></Row><Divider> 幽灵按钮 </Divider><Row :gutter="32"><Col span="2"><Button ghost>按钮11</Button></Col><Col span="2"><Button type="primary" ghost>按钮12</Button></Col><Col span="2"><Button type="dashed" ghost>按钮13</Button></Col><Col span="2"><Button type="text" ghost>按钮14</Button></Col><Col span="2"><Button type="info" ghost>按钮15</Button></Col><Col span="2"><Button type="success" ghost>按钮16</Button></Col><Col span="2"><Button type="warning" ghost>按钮17</Button></Col><Col span="2"><Button type="error" ghost>按钮18</Button></Col></Row><Divider> 圆角按钮 </Divider><Row :gutter="32"><Col span="2"><Button shape="circle">按钮21</Button></Col><Col span="2"><Button type="primary" shape="circle">按钮22</Button></Col><Col span="2"><Button type="dashed" shape="circle">按钮23</Button></Col><Col span="2"><Button type="text" shape="circle">按钮24</Button></Col><Col span="2"><Button type="info" shape="circle">按钮25</Button></Col><Col span="2"><Button type="success" shape="circle">按钮26</Button></Col><Col span="2"><Button type="warning" shape="circle">按钮27</Button></Col><Col span="2"><Button type="error" shape="circle">按钮28</Button></Col></Row><Divider> 带图标圆角按钮 </Divider><Row :gutter="32"><Col span="2"><Button shape="circle" icon="ios-wifi">按钮31</Button></Col><Col span="2"><Button type="primary" shape="circle" icon="ios-wifi">按钮32</Button></Col><Col span="2"><Button type="dashed" shape="circle" icon="ios-wifi">按钮33</Button></Col><Col span="2"><Button type="text" shape="circle" icon="ios-wifi">按钮34</Button></Col><Col span="2"><Button type="info" shape="circle" icon="ios-wifi">按钮35</Button></Col><Col span="2"><Button type="success" shape="circle" icon="ios-wifi">按钮36</Button></Col><Col span="2"><Button type="warning" shape="circle" icon="ios-wifi">按钮37</Button></Col><Col span="2"><Button type="error" shape="circle" icon="ios-wifi">按钮38</Button></Col></Row><Divider> 纯图标圆角按钮 </Divider><Row :gutter="32"><Col span="2"><Button shape="circle" icon="ios-wifi"></Button></Col><Col span="2"><Button type="primary" shape="circle" icon="ios-wifi"></Button></Col><Col span="2"><Button type="dashed" shape="circle" icon="ios-wifi"></Button></Col><Col span="2"><Button type="text" shape="circle" icon="ios-wifi"></Button></Col><Col span="2"><Button type="info" shape="circle" icon="ios-wifi"></Button></Col><Col span="2"><Button type="success" shape="circle" icon="ios-wifi"></Button></Col><Col span="2"><Button type="warning" shape="circle" icon="ios-wifi"></Button></Col><Col span="2"><Button type="error" shape="circle" icon="ios-wifi"></Button></Col></Row><Divider> 大尺寸圆角按钮 </Divider><Row :gutter="32"><Col span="2"><Button shape="circle" icon="ios-wifi" size="large">按钮51</Button></Col><Col span="2"><Button type="primary" shape="circle" icon="ios-wifi" size="large">按钮52</Button></Col><Col span="2"><Button type="dashed" shape="circle" icon="ios-wifi" size="large">按钮53</Button></Col><Col span="2"><Button type="text" shape="circle" icon="ios-wifi" size="large">按钮54</Button></Col><Col span="2"><Button type="info" shape="circle" icon="ios-wifi" size="large">按钮55</Button></Col><Col span="2"><Button type="success" shape="circle" icon="ios-wifi" size="large">按钮56</Button></Col><Col span="2"><Button type="warning" shape="circle" icon="ios-wifi" size="large">按钮57</Button></Col><Col span="2"><Button type="error" shape="circle" icon="ios-wifi" size="large">按钮58</Button></Col></Row><Divider> 拉长型圆角按钮 </Divider><Row :gutter="32"><Col span="2"><Button shape="circle" icon="ios-wifi" size="large" long>按钮61</Button></Col><Col span="2"><Button type="primary" shape="circle" icon="ios-wifi" size="large" long>按钮62</Button></Col><Col span="2"><Button type="dashed" shape="circle" icon="ios-wifi" size="large" long>按钮63</Button></Col><Col span="2"><Button type="text" shape="circle" icon="ios-wifi" size="large" long>按钮64</Button></Col><Col span="2"><Button type="info" shape="circle" icon="ios-wifi" size="large" long>按钮65</Button></Col><Col span="2"><Button type="success" shape="circle" icon="ios-wifi" size="large" long>按钮66</Button></Col><Col span="2"><Button type="warning" shape="circle" icon="ios-wifi" size="large" long>按钮67</Button></Col><Col span="2"><Button type="error" shape="circle" icon="ios-wifi" size="large" long>按钮68</Button></Col></Row><Divider> 加载按钮 </Divider><Row :gutter="32"><Col span="2"><Button shape="circle" icon="ios-wifi" size="large" loading>按钮71</Button></Col><Col span="2"><Button type="primary" shape="circle" icon="ios-wifi" size="large" loading>按钮72</Button></Col><Col span="2"><Button type="dashed" shape="circle" icon="ios-wifi" size="large" loading>按钮73</Button></Col><Col span="2"><Button type="text" shape="circle" icon="ios-wifi" size="large" loading>按钮74</Button></Col><Col span="2"><Button type="info" shape="circle" icon="ios-wifi" size="large" loading>按钮75</Button></Col><Col span="2"><Button type="success" shape="circle" icon="ios-wifi" size="large" loading>按钮76</Button></Col><Col span="2"><Button type="warning" shape="circle" icon="ios-wifi" size="large" loading>按钮77</Button></Col><Col span="2"><Button type="error" shape="circle" icon="ios-wifi" size="large" loading>按钮78</Button></Col></Row><Divider> 禁用按钮 </Divider><Row :gutter="32"><Col span="2"><Button shape="circle" icon="ios-wifi" size="large" disabled>按钮81</Button></Col><Col span="2"><Button type="primary" shape="circle" icon="ios-wifi" size="large" disabled>按钮82</Button></Col><Col span="2"><Button type="dashed" shape="circle" icon="ios-wifi" size="large" disabled>按钮83</Button></Col><Col span="2"><Button type="text" shape="circle" icon="ios-wifi" size="large" disabled>按钮84</Button></Col><Col span="2"><Button type="info" shape="circle" icon="ios-wifi" size="large" disabled>按钮85</Button></Col><Col span="2"><Button type="success" shape="circle" icon="ios-wifi" size="large" disabled>按钮86</Button></Col><Col span="2"><Button type="warning" shape="circle" icon="ios-wifi" size="large" disabled>按钮87</Button></Col><Col span="2"><Button type="error" shape="circle" icon="ios-wifi" size="large" disabled>按钮88</Button></Col></Row><Divider> 按钮组合 </Divider><Row :gutter="32"><Col span="4"><ButtonGroup><Button shape="circle" icon="ios-wifi" size="large">按钮91-1</Button><Button type="primary" shape="circle" icon="ios-wifi" size="large">按钮91-2</Button></ButtonGroup></Col><Col span="8"><ButtonGroup size="large"><Button type="dashed" shape="circle" icon="ios-wifi" size="large">按钮92-1</Button><Button type="text" shape="circle" icon="ios-wifi" size="large">按钮92-2</Button><Button type="info" shape="circle" icon="ios-wifi" size="large">按钮92-3</Button><Button type="success" shape="circle" icon="ios-wifi" size="large">按钮92-4</Button></ButtonGroup></Col><Col span="4"><ButtonGroup><Button type="warning" shape="circle" icon="ios-wifi" size="large">按钮93-1</Button><Button type="error" shape="circle" icon="ios-wifi" size="large">按钮93-2</Button></ButtonGroup></Col></Row></div>
</template><script>
export default {name: 'test',
}
</script><style scoped>
.hello {background-color: rgb(224, 249, 250);
}
</style>

Vue组件库 View UI 来看看这80种奇奇怪怪的按钮相关推荐

  1. vue组件库介绍以及组件库Element UI 的使用

    组件库 前言 这篇文章介绍vue组件库! 介绍什么是组件库以及Element UI组件库的使用! 看完不会你打我.哈哈哈,开玩笑的,不多说,上刺刀!! 1. 什么是 vue 组件库 在实际开发中,前端 ...

  2. vue统计组件库和ui框架

    element ★13489 - 饿了么出品的Vue2的web UI工具套件 Vux ★8133 - 基于Vue和WeUI的组件库 iview ★6634 - 基于 Vuejs 的开源 UI 组件库 ...

  3. UI组件库Kendo UI for Vue中文入门指南(四)

    在本文中,您将通过构建一个包含 Grid.DropDownList.Window 和设计主题的小应用程序来学习如何使用Kendo UI for Vue组件. Kendo UI最新官方正式版下载 7. ...

  4. vant官网-vant ui 首页-移动端Vue组件库

    Vant 是有赞前端团队开源的移动端vue组件库,适用于手机端h5页面. 鉴于百度搜索不到vant官方网址,分享一下vant组件库官网地址,方便新手使用 vant官网地址https://vant-co ...

  5. UI组件库Kendo UI for Vue中文入门指南(二)

    在本文中,您将通过构建一个包含 Grid.DropDownList.Window 和设计主题的小应用程序来学习如何使用Kendo UI for Vue组件. Kendo UI最新官方正式版下载 5. ...

  6. UI组件库Kendo UI for Vue中文入门指南(一)

    在本文中,您将通过构建一个包含 Grid.DropDownList.Window 和设计主题的小应用程序来学习如何使用Kendo UI for Vue组件. Kendo UI最新官方正式版下载 1. ...

  7. Vant 1.0 发布:轻量、可靠的移动端 Vue 组件库

    Vant 是有赞前端团队维护的移动端 Vue 组件库,提供了一整套 UI 基础组件和业务组件.通过 Vant 可以快速搭建出风格统一的页面,提升开发效率. Vant 一.关于 1.0 距离 Vant ...

  8. 十多款优秀的Vue组件库介绍

    十多款优秀的Vue组件库介绍 1. iView UI组件库 iView 是一套基于 Vue.js 的开源 UI 组件库,主要服务于 PC 界面的中后台产品.iView的组件还是比较齐全的,更新也很快, ...

  9. GitChat · 前端 | Vue 组件库实践和设计

    来自 GitChat 作者:周志祥 更多IT技术分享,尽在微信公众号:GitChat技术杂谈 前言 现在前端的快速发展,已经让组件这个模式变的格外重要.对于市面上的组件库,虽然能满足大部分的项目,但是 ...

最新文章

  1. 一张图看懂CSS cascade, specific, importance, inheritance
  2. php study 直接显示代码_PHP获取文件大小的方法详解(附视频)
  3. 查看并开启MySQL的log-bin和general_log日志
  4. iOS截取特定的字符串(正则匹配)
  5. html5中meter讲解_Java中的得墨meter耳定律–最少知识原理–实际示例
  6. Android 调整屏幕分辩率
  7. 二分查找:在有序数组中搜索大于等于x的数的最小下标
  8. 解决python访问中突发requests.exceptions.ConnectionError:Max retries exceeded with url报错
  9. 苏宁易购发全员信:双十一销售目标全面完成 力争11月EBITDA转正
  10. [学习备忘录]Linux平台静态库、动态库的一些笔记
  11. angular获取图片高宽_Angular 读书笔记
  12. 敏捷开发免费管理工具——火星人预览之五:常见问题问答
  13. html 空间扭曲效果,3DS MAX空间扭曲工具基础教程
  14. java变量和常量_java变量和常量的区别是什么
  15. 三个下载原版Windows镜像的方法
  16. 毕业论文的页眉、页脚以及参考文献插入经验分享
  17. 出口退税的操作明细流程
  18. 抖音xlog算法解析
  19. 阿里云的这群疯子--深度好文成功绝非偶然
  20. 自我管理的29个工具

热门文章

  1. 京东数据中心主要基础设施系统(一)
  2. jQuery设置按钮的属性_可用不可用
  3. python怎么多行输入_python如何输入多行
  4. 2021 年,Python 开发者用什么操作系统最香?
  5. ATFX:离岸人民币破6.9,距离整数关口7仅一步之遥
  6. 谷歌审查元素获取网络资源链接
  7. N多计算机精品免费视频下载
  8. python怎么建立画板_Python3使用PyQt5制作简单的画板/手写板实例
  9. Linux设置支持中文
  10. Oracle工具包使用规则整理