ref.uvue 647 字节
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 12 13 14 15 16 17 18 19 20
  const count1 = ref(0)
  const count2 = ref(count1)

  type Counter = {
    count : number
  }
  const counter = ref({
    count: 0
  } as Counter)

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