switch.uvue 2.1 KB
Newer Older
H
hdx 已提交
1
<template>
2 3
  <view>
    <view class="uni-padding-wrap uni-common-mt">
H
hdx 已提交
4 5
      <view class="uni-title">默认样式</view>
      <view class="flex-row">
H
hdx 已提交
6
        <switch class="switch-checked" :checked="checked" @change="switch1Change" />
H
hdx 已提交
7
        <switch @change="switch2Change" />
H
hdx 已提交
8
        <!-- <text class="switch-checked-value">{{clickCheckedValue}}</text> -->
H
hdx 已提交
9
      </view>
H
hdx 已提交
10 11 12 13 14
      <view class="uni-title">禁用样式</view>
      <view class="flex-row">
        <switch class="switch-checked" :checked="checked" :disabled="true" />
        <switch :disabled="true" />
      </view>
H
hdx 已提交
15 16
      <view class="uni-title">不同颜色和尺寸的switch</view>
      <view class="flex-row">
H
hdx 已提交
17 18
        <switch class="switch-color-checked" :color="color" style="transform:scale(0.7)" :checked="true" />
        <switch class="switch-color" :color="color" style="transform:scale(0.7)" />
H
hdx 已提交
19 20 21 22
      </view>
      <view class="uni-title">推荐展示样式</view>
    </view>
    <view class="uni-list">
23
      <view class="uni-list-cell uni-list-cell-padding">
H
hdx 已提交
24 25 26
        <view class="uni-list-cell-db">开启中</view>
        <switch :checked="true" />
      </view>
27
      <view class="uni-list-cell uni-list-cell-padding">
H
hdx 已提交
28 29 30 31 32 33 34
        <view class="uni-list-cell-db">关闭</view>
        <switch />
      </view>
    </view>
  </view>
</template>

Y
yurj26 已提交
35
<script lang="uts">
H
hdx 已提交
36 37 38
  export default {
    data() {
      return {
H
hdx 已提交
39 40 41
        title: 'switch 开关',
        checked: true,
        color: '#FFCC33',
42 43
        clickCheckedValue: true,
        testVerifyEvent: false,
H
hdx 已提交
44 45 46
      }
    },
    methods: {
H
hdx 已提交
47
      switch1Change: function (e : UniSwitchChangeEvent) {
H
hdx 已提交
48
        this.clickCheckedValue = e.detail.value
H
hdx 已提交
49
        console.log('switch1 发生 change 事件,携带值为', e.detail.value)
50 51 52

        // 仅测试
        this.testVerifyEvent = (e.type == 'change' && (e.target?.tagName ?? '') == "SWITCH")
H
hdx 已提交
53
      },
H
hdx 已提交
54
      switch2Change: function (e : UniSwitchChangeEvent) {
H
hdx 已提交
55 56 57 58 59 60 61 62 63 64
        console.log('switch2 发生 change 事件,携带值为', e.detail.value)
      }
    }
  }
</script>

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