switch.uvue 1.4 KB
Newer Older
H
hdx 已提交
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
<template>
  <view class="uni-padding-wrap">
    <view class="uni-common-mt">
      <view class="uni-title">默认样式</view>
      <view class="flex-row">
        <switch :checked="true" @change="switch1Change" />
        <switch @change="switch2Change" />
      </view>
      <view class="uni-title">不同颜色和尺寸的switch</view>
      <view class="flex-row">
        <switch color="#FFCC33" style="transform:scale(0.7)" :checked="true" />
        <switch color="#FFCC33" style="transform:scale(0.7)" />
      </view>
      <view class="uni-title">推荐展示样式</view>
    </view>
    <view class="uni-list">
      <view class="uni-list-cell uni-list-cell-pd">
        <view class="uni-list-cell-db">开启中</view>
        <switch :checked="true" />
      </view>
      <view class="uni-list-cell uni-list-cell-pd">
        <view class="uni-list-cell-db">关闭</view>
        <switch />
      </view>
    </view>
  </view>
</template>

<script lang="ts">
  export default {
    data() {
      return {
        title: 'switch 开关'
      }
    },
    methods: {
      switch1Change: function (e : SwitchChangeEvent) {
        console.log('switch1 发生 change 事件,携带值为', e.detail.value)
      },
      switch2Change: function (e : SwitchChangeEvent) {
        console.log('switch2 发生 change 事件,携带值为', e.detail.value)
      }
    }
  }
</script>

<style>
  .flex-row {
    flex-direction: row;
  }
</style>