提交 77c0ab89 编写于 作者: DCloud-WZF's avatar DCloud-WZF 💬

feat(composition api): shallowRef

上级 a16a03ac
const PAGE_PATH = '/pages/composition-api/reactivity/shallow-ref/shallow-ref'
describe('shallowRef', () => {
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 stateCount = await page.$('#state-count')
expect(await stateCount.text()).toBe('state.count: 0')
const incrementStateCountBtn = await page.$('#increment-state-count-btn')
await incrementStateCountBtn.tap()
expect(await stateCount.text()).toBe('state.count: 0')
const updateStateBtn = await page.$('#update-state-btn')
await updateStateBtn.tap()
expect(await stateCount.text()).toBe('state.count: 1')
})
} else {
it('other platform', () => {
expect(1).toBe(1)
})
}
})
\ No newline at end of file
<template><view class="page">shallowRef</view></template>
\ No newline at end of file
<template>
<view class="page">
<text id="state-count" class="uni-common-mb">state.count: {{ state.count }}</text>
<button id="increment-state-count-btn" class="uni-common-mb" @click="incrementStateCount">increment
state.count</button>
<button id="update-state-btn" @click="updateState">update state</button>
</view>
</template>
<script setup>
type State = {
count: number
}
const state = shallowRef({
count: 0
} as State)
const incrementStateCount = () => {
state.value.count++
}
const updateState = () => {
state.value = { count: state.value.count } as State
}
</script>
\ No newline at end of file
......@@ -166,7 +166,7 @@
{
name: 'shallowRef',
url: 'shallow-ref',
enable: false,
enable: true,
},
{
name: 'triggerRef',
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册