index.vue 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. <template>
  2. <view
  3. class="c-button c-button-txt"
  4. @click="$emit('click')"
  5. v-if="type === 'text'"
  6. >
  7. <!-- $slots获取不到#default -->
  8. <template v-for="(_, name) in $scopedSlots">
  9. <slot :name="name"></slot>
  10. </template>
  11. </view>
  12. <u-button
  13. class="c-button"
  14. v-else
  15. v-bind="newAttrs"
  16. v-on="$listeners"
  17. >
  18. <slot></slot>
  19. </u-button>
  20. </template>
  21. <script>
  22. import uProps from 'uview-ui/components/u-button/props';
  23. const customProps = {}; // 自定义的props
  24. export default {
  25. name: 'cButton',
  26. props: {
  27. // 按钮的预置样式,info,primary,error,warning,success
  28. type: {
  29. type: String,
  30. default: uni.$u.props.button.type,
  31. },
  32. ...uProps,
  33. ...customProps,
  34. },
  35. computed: {
  36. newAttrs() {
  37. return {
  38. ...this.$attrs,
  39. ...this.$props,
  40. };
  41. },
  42. },
  43. methods: {},
  44. };
  45. </script>
  46. <style scoped lang="scss">
  47. .c-button-txt {
  48. font-size: 14px;
  49. color: #3c9cff;
  50. }
  51. .u-button--primary {
  52. color: #fff;
  53. background-color: #436ff6;
  54. border-color: #436ff6;
  55. border-width: 1px;
  56. border-style: solid;
  57. }
  58. .u-button--disabled {
  59. background-color: #969696 !important;
  60. color: #fff !important;
  61. border: 0;
  62. box-shadow: 0px 2px 6px 0px rgba(150, 150, 150, 0.42);
  63. }
  64. </style>