提交 9a05658e 编写于 作者: DCloud-WZF's avatar DCloud-WZF 💬

feat(composition api): ref

上级 0f2932f0
const PAGE_PATH = '/pages/composition-api/reactivity/ref/ref'
describe('ref', () => {
if (process.env.uniTestPlatformInfo.startsWith('android')) {
let page = null
beforeAll(async () => {
page = await program.reLaunch(PAGE_PATH)
await page.waitFor('view')
})
it('basic', async () => {
const count1 = await page.$('#count1')
expect(await count1.text()).toBe('count1: 0')
const count2 = await page.$('#count2')
expect(await count2.text()).toBe('count2: 0')
const counterCount = await page.$('#counter-count')
expect(await counterCount.text()).toBe('counter.count: 0')
const incrementBtn = await page.$('#increment-btn')
await incrementBtn.tap()
expect(await count1.text()).toBe('count1: 2')
expect(await count2.text()).toBe('count2: 2')
expect(await counterCount.text()).toBe('counter.count: 1')
})
} else {
it('other platform', () => {
expect(1).toBe(1)
})
}
})
\ No newline at end of file
<template>
<view class="page">
<text id="count" class="uni-common-mb">count: {{ count }}</text>
<text id="count1" class="uni-common-mb">count1: {{ count1 }}</text>
<text id="count2" class="uni-common-mb">count2: {{ count2 }}</text>
<text id="counter-count" class="uni-common-mb">counter.count: {{ counter.count }}</text>
<button id="increment-btn" @click="increment">increment</button>
</view>
</template>
<script setup>
const count = ref(0)
const count1 = ref(0)
const count2 = ref(count1)
type Counter = {
count : number
}
const counter = ref({
count: 0
} as Counter)
const increment = () => {
count.value++
count1.value++
count2.value++
counter.value.count++
}
</script>
\ No newline at end of file
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册