ref.uvue 756 字节
Newer Older
1 2
<template>
  <view class="page">
3 4 5
    <text id="count1" class="mb-10">count1: {{ count1 }}</text>
    <text id="count2" class="mb-10">count2: {{ count2 }}</text>
    <text id="counter-count" class="mb-10">counter.count: {{ counter.count }}</text>
6
    <button class="increment-btn" @click="increment">increment</button>
7 8 9
  </view>
</template>

10
<script setup lang='uts'>
DCloud-WZF's avatar
DCloud-WZF 已提交
11
  // 基础数据类型可自动推导类型
DCloud-WZF's avatar
DCloud-WZF 已提交
12 13 14 15 16 17
  const count1 = ref(0)
  const count2 = ref(count1)

  type Counter = {
    count : number
  }
DCloud-WZF's avatar
DCloud-WZF 已提交
18
  // TODO: Android 待编译器支持通过泛型指定类型
DCloud-WZF's avatar
DCloud-WZF 已提交
19 20 21 22
  const counter = ref({
    count: 0
  } as Counter)

23
  const increment = () => {
DCloud-WZF's avatar
DCloud-WZF 已提交
24 25 26
    count1.value++
    count2.value++
    counter.value.count++
27 28
  }
</script>