dynamic-border.uvue 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. <template>
  2. <!-- #ifdef APP -->
  3. <scroll-view style="flex: 1">
  4. <!-- #endif -->
  5. <view style="margin: 15px;border-radius: 10px;background-color: white;">
  6. <view v-for="index in [0,1,2,3,4,5,6,7,8,9]" :key="index"
  7. :class="(index < 9 ? 'bb1' : '') + ' ' + (currentIndex == 0 ? 'btlr10 btrr10' : currentIndex == 9 ? 'bblr10 bbrr10' : '')"
  8. style="flex-direction: row;align-items: center;padding: 15px"
  9. :style="index == currentIndex ? 'background-color :#57BE6A;' : ''" @tap="changeIndex(index)">
  10. <view>
  11. <text style="font-size: 14px;" :style="index == currentIndex ? 'color: #FFFFFF;' : ''">{{ index }}</text>
  12. </view>
  13. </view>
  14. </view>
  15. <view style="margin: 15px;margin-top: 20px;">
  16. <text>动态切换 border 为空值</text>
  17. <text @click="setBorderBlank" class="common" :style="style">
  18. {{isSelect?'选中':'未选中'}}
  19. </text>
  20. </view>
  21. <!-- #ifdef APP -->
  22. </scroll-view>
  23. <!-- #endif -->
  24. </template>
  25. <script>
  26. const defaultStyle = 'border:2px solid black;background :#57BE6A;'
  27. export default {
  28. data() {
  29. return {
  30. currentIndex: 0,
  31. style: '' as string,
  32. }
  33. },
  34. computed: {
  35. isSelect() : boolean {
  36. return this.style == defaultStyle
  37. }
  38. },
  39. methods: {
  40. changeIndex(index : number) {
  41. this.currentIndex = index
  42. },
  43. setBorderBlank() {
  44. this.style = this.style == '' ? defaultStyle : ''
  45. }
  46. }
  47. }
  48. </script>
  49. <style>
  50. .common {
  51. padding: 15px;
  52. border-radius: 4px;
  53. width: 120px;
  54. text-align: center;
  55. margin-top: 10px;
  56. }
  57. .bb1 {
  58. border-bottom: 1rpx solid #EEEEEE;
  59. }
  60. .btlr10 {
  61. border-top-left-radius: 10rpx;
  62. }
  63. .btrr10 {
  64. border-top-right-radius: 10rpx;
  65. }
  66. .bblr10 {
  67. border-bottom-left-radius: 10rpx;
  68. }
  69. .bbrr10 {
  70. border-bottom-right-radius: 10rpx;
  71. }
  72. </style>