<button>

<button> 是一个预设常用按钮。

子组件

预览效果

&lt;button&gt; - 图1

示例代码

  1. <template>
  2. <div class="app">
  3. <scroller class="list">
  4. <text class="list-title">预设样式</text>
  5. <div class="list-item">
  6. <button class="button" text="默认"></button>
  7. <button class="button" text="红色" model="red"></button>
  8. </div>
  9. <div class="list-item">
  10. <button class="button" text="绿色" model="green"></button>
  11. <button class="button" text="蓝色" model="blue"></button>
  12. </div>
  13. <div class="list-item">
  14. <button class="button" text="粉红" model="pink"></button>
  15. <button class="button" text="黄色" model="yellow"></button>
  16. </div>
  17. <div class="list-item">
  18. <button class="button" text="橙色" model="orange"></button>
  19. <button class="button" text="灰色" model="gray"></button>
  20. </div>
  21. <div class="list-item">
  22. <button class="button" text="黑色" model="black"></button>
  23. <button class="button" text="白色" model="white"></button>
  24. </div>
  25. <div class="list-item">
  26. <button class="button" text="加载中" loading="true"></button>
  27. <button class="button" text="禁用" disabled="true"></button>
  28. </div>
  29. <text class="list-title">自定义样式</text>
  30. <div class="list-input-item">
  31. <text class="cell">按钮文字:</text>
  32. <input class="input" placeholder="文字" v-model="text"/>
  33. </div>
  34. <div class="list-input-item">
  35. <text class="cell" style="flex:1">是否加载中:</text>
  36. <switch class="switch" :checked="loading" @change="loading = !loading"></switch>
  37. </div>
  38. <div class="list-input-item">
  39. <text class="cell" style="flex:1">是否禁用:</text>
  40. <switch class="switch" :checked="disabled" @change="disabled = !disabled"></switch>
  41. </div>
  42. <div class="list-input-item">
  43. <text class="cell">按钮宽度:</text>
  44. <input class="input" placeholder="自定义样式实现, 默认全屏"
  45. v-model="width"/>
  46. </div>
  47. <div class="list-input-item">
  48. <text class="cell">按钮高度:</text>
  49. <input class="input" placeholder="自定义样式实现, 默认高度80px" v-model="height"/>
  50. </div>
  51. <div class="list-input-item">
  52. <text class="cell">背景颜色:</text>
  53. <input class="input" placeholder="自定义样式实现" v-model="backgroundColor"/>
  54. </div>
  55. <div class="list-input-item">
  56. <text class="cell">边框颜色:</text>
  57. <input class="input" placeholder="自定义样式实现" v-model="borderColor"/>
  58. </div>
  59. <div class="list-input-item">
  60. <text class="cell">边框圆角:</text>
  61. <input class="input" placeholder="自定义样式实现,默认8px" v-model="borderRadius"/>
  62. </div>
  63. <div class="demo-item">
  64. <button class="demoButton" :eeui="eeuiStyle" :style="demoStyle"></button>
  65. </div>
  66. </scroller>
  67. </div>
  68. </template>
  69. <style scoped>
  70. .app {
  71. width: 750px;
  72. flex: 1;
  73. background-color: #ffffff;
  74. }
  75. .list {
  76. width: 750px;
  77. flex: 1;
  78. }
  79. .list-title {
  80. margin-top: 24px;
  81. margin-bottom: 12px;
  82. padding-top: 36px;
  83. padding-right: 24px;
  84. padding-bottom: 24px;
  85. padding-left: 24px;
  86. font-size: 28px;
  87. color: #757575;
  88. }
  89. .list-item {
  90. width: 750px;
  91. flex-direction: row;
  92. }
  93. .button {
  94. font-size: 24px;
  95. margin-left: 37.5px;
  96. margin-right: 37.5px;
  97. margin-bottom: 20px;
  98. width: 300px;
  99. height: 80px;
  100. }
  101. .list-input-item {
  102. width: 750px;
  103. height: 90px;
  104. flex-direction: row;
  105. align-items: center;
  106. border-bottom-color: #e4e4e4;
  107. border-bottom-style: solid;
  108. border-bottom-width: 1px;
  109. }
  110. .cell {
  111. padding-left: 50px;
  112. font-size: 24px;
  113. color: #666666;
  114. }
  115. .switch {
  116. margin-right: 40px;
  117. }
  118. .input {
  119. padding-right: 50px;
  120. flex: 1;
  121. height: 90px;
  122. text-align: right;
  123. font-size: 28px;
  124. }
  125. .demo-item {
  126. width: 750px;
  127. padding-top: 30px;
  128. padding-bottom: 30px;
  129. align-items: center;
  130. }
  131. </style>
  132. <script>
  133. const eeui = app.requireModule('eeui');
  134. export default {
  135. data() {
  136. return {
  137. text: '按钮',
  138. width: '702px',
  139. height: '80px',
  140. loading: false,
  141. disabled: false,
  142. backgroundColor: '#FF5000',
  143. borderColor: '#FF5000',
  144. borderRadius: '8px',
  145. fontSize: '28px',
  146. color: '#FFFFFF'
  147. }
  148. },
  149. mounted() {
  150. this.$nextTick(() => {
  151. this.text = '按钮文字';
  152. });
  153. },
  154. computed: {
  155. eeuiStyle() {
  156. const { backgroundColor, borderColor, borderRadius, text, color, loading, disabled } = this;
  157. const customStyle = {};
  158. if (backgroundColor) {
  159. customStyle.backgroundColor = backgroundColor;
  160. }
  161. if (borderColor) {
  162. customStyle.borderColor = borderColor;
  163. customStyle.borderWidth = "1px";
  164. }
  165. if (borderRadius) {
  166. customStyle.borderRadius = borderRadius;
  167. }
  168. if (text) {
  169. customStyle.text = text;
  170. }
  171. if (color) {
  172. customStyle.color = color;
  173. }
  174. customStyle.loading = loading;
  175. customStyle.disabled = disabled;
  176. return customStyle;
  177. },
  178. demoStyle() {
  179. const { width, height } = this;
  180. const customStyle = {};
  181. customStyle.width = width;
  182. customStyle.height = height;
  183. return customStyle;
  184. }
  185. },
  186. };
  187. </script>

配置参数

属性名 类型 描述 默认值
text String 按钮文字 -
color String 按钮文字颜色 #FFFFFF
fontSize Number 字体大小 -
backgroundColor String 按钮背景颜色 #3EB4FF
borderRadius Number 圆角半径 8
borderWidth Number 边框大小 0
borderColor String 边框颜色 -
disabled Boolean 是否禁用 false
loading Boolean 是否加载中 false
model String 预设风格,详细注① -

注①

red:红色;green:绿色;blue:蓝色;pink:粉红;

yellow:黄色;orange:橙色;gray:灰色;black:黑色;white:白色;

例如:

  1. <button
  2. ref="reflectName"
  3. class="button"
  4. text="红色" model="red"></button>

事件回调 callback

  1. /**
  2. * 组件加载完成
  3. */
  4. @ready = function() { ... }

调用方法 methods

  1. /**
  2. * 设置按钮文字
  3. * 参数一:按钮文字
  4. */
  5. this.$refs.reflectName.setText('文字');
  6. /**
  7. * 设置按钮文字颜色
  8. * 参数一:颜色代码
  9. */
  10. this.$refs.reflectName.setTextColor('#FF0000');
  11. /**
  12. * 设置按钮字体大小
  13. * 参数一:字体大小
  14. */
  15. this.$refs.reflectName.setTextSize(20);
  16. /**
  17. * 设置是否禁用
  18. * 参数一:true|false
  19. */
  20. this.$refs.reflectName.setDisabled(true);
  21. /**
  22. * 设置是否加载中
  23. * 参数一:true|false
  24. */
  25. this.$refs.reflectName.setLoading(true);