dynamic-border.uvue 1.9 KB
Newer Older
DCloud-WZF's avatar
DCloud-WZF 已提交
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81
<template>
  <!-- #ifdef APP -->
  <scroll-view style="flex: 1">
  <!-- #endif -->
    <view style="margin: 15px;border-radius: 10px;background-color: white;">
      <view v-for="index in 10" :key="index"
        :class="(index < 9 ? 'bb1' : '') + ' ' + (currentIndex == 0 ? 'btlr10 btrr10' : currentIndex == 9 ? 'bblr10 bbrr10' : '')"
        style="flex-direction: row;align-items: center;padding: 15px"
        :style="index == currentIndex ? 'background-color :#57BE6A;' : ''" @tap="currentIndex = index">
        <view>
          <text style="font-size: 14px;" :style="index == currentIndex ? 'color: #FFFFFF;' : ''">{{ index }}</text>
        </view>
      </view>


    </view>
    <view style="margin: 15px;margin-top: 20px;">
      <text>动态切换 border 为空值</text>
      <text @click="setBorderBlank" class="common" :style="style">
        {{isSelect?'选中':'未选中'}}
      </text>
    </view>
  <!-- #ifdef APP -->
  </scroll-view>
  <!-- #endif -->
</template>

<script>
  const defaultStyle = 'border:2px solid black;background :#57BE6A;'
  export default {

    data() {
      return {
        currentIndex: 1,
        style: '' as string,
      }
    },
    computed: {
      isSelect() : boolean {
        return this.style == defaultStyle
      }
    },
    methods: {
      changeIndex(index : number) {
        this.currentIndex = index
      },
      setBorderBlank() {
        this.style = this.style == '' ? defaultStyle : ''
      }
    }
  }
</script>

<style>
  .common {
    padding: 15px;
    border-radius: 4px;
    width: 120px;
    text-align: center;
    margin-top: 10px;
  }

  .bb1 {
    border-bottom: 1rpx solid #EEEEEE;
  }

  .btlr10 {
    border-top-left-radius: 10rpx;
  }

  .btrr10 {
    border-top-right-radius: 10rpx;
  }

  .bblr10 {
    border-bottom-left-radius: 10rpx;
  }

  .bbrr10 {
    border-bottom-right-radius: 10rpx;
  }
82
</style>