button.vue 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. <template>
  2. <view class="button-container" style="margin-top: 200rpx;">
  3. <button class="button" @click="handleClick">
  4. <view class="button-left">
  5. <text class="button-text">免费领</text>
  6. </view>
  7. <view class="button-right">
  8. <text class="button-remain">样品剩余{{ remain }}个</text>
  9. </view>
  10. <image src="https://horastar.obs.cn-east-3.myhuaweicloud.com/youngee/talent_upload/button_flash.png" class="button-icon"></image>
  11. </button>
  12. </view>
  13. </template>
  14. <script>
  15. export default {
  16. data() {
  17. return {
  18. remain: 100 // 这是一个示例数值,你可以通过接口获取并动态更新这个值
  19. };
  20. },
  21. methods: {
  22. handleClick() {
  23. // 处理按钮点击事件
  24. console.log('按钮被点击了');
  25. // 在这里添加点击后的逻辑,例如跳转页面或发送请求
  26. uni.showToast({
  27. title: '按钮被点击了',
  28. icon: 'none'
  29. });
  30. }
  31. },
  32. mounted() {
  33. // 示例请求,你需要根据实际接口地址和返回数据结构进行修改
  34. uni.request({
  35. url: 'https://your-api-endpoint.com/get-remaining-samples',
  36. success: (res) => {
  37. this.remain = res.data.remain; // 假设接口返回的数据结构中有remain字段
  38. },
  39. fail: (err) => {
  40. console.error(err);
  41. }
  42. });
  43. }
  44. };
  45. </script>
  46. <style>
  47. .button-container {
  48. display: flex;
  49. align-items: center;
  50. justify-content: center;
  51. }
  52. .button {
  53. display: flex;
  54. align-items: center;
  55. border-radius: 20px;
  56. padding: 5px;
  57. border: none; /* 使 button 边框消失 */
  58. background-color: transparent; /* 背景透明 */
  59. position: relative; /* 相对定位以便图标定位 */
  60. }
  61. .button-left {
  62. display: flex;
  63. align-items: center;
  64. background-color: #ff4d4d;
  65. border-top-left-radius: 20px;
  66. border-bottom-left-radius: 20px;
  67. padding: 10px 15px;
  68. }
  69. .button-right {
  70. display: flex;
  71. align-items: center;
  72. background-color: #ffe8d8;
  73. border-top-right-radius: 20px;
  74. border-bottom-right-radius: 20px;
  75. padding: 10px 15px;
  76. }
  77. .button-text {
  78. color: white;
  79. font-weight: bold;
  80. }
  81. .button-icon {
  82. width: 100rpx;
  83. height: 180rpx;
  84. position: absolute;
  85. top: 50%;
  86. left: 38%;
  87. transform: translate(-50%, -50%);
  88. z-index: 10; /* 确保图标在最上层 */
  89. }
  90. .button-remain {
  91. color: #a9a9a9;
  92. }
  93. </style>