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

refactor(reactivity): shallowRef

上级 96eabdd6
......@@ -612,6 +612,11 @@ export default {
name: 'shallowReadonly',
url: 'shallow-readonly/shallow-readonly'
},
{
id: 'shallow-ref',
name: 'shallowRef',
url: 'shallow-ref/shallow-ref'
},
]
}
] as Page[]
......
const PAGE_PATH = '/pages/composition-api/reactivity/shallow-ref/shallow-ref'
const PAGE_PATH = '/pages/reactivity/advanced/shallow-ref/shallow-ref'
describe('shallowRef', () => {
let page = null
......@@ -8,16 +8,16 @@ describe('shallowRef', () => {
})
it('basic', async () => {
const stateCount = await page.$('#state-count')
expect(await stateCount.text()).toBe('state.count: 0')
expect(await stateCount.text()).toBe('0')
const incrementStateCountBtn = await page.$('.increment-state-count-btn')
await incrementStateCountBtn.tap()
expect(await stateCount.text()).toBe('state.count: 0')
expect(await stateCount.text()).toBe('0')
const updateStateBtn = await page.$('.update-state-btn')
await updateStateBtn.tap()
expect(await stateCount.text()).toBe('state.count: 1')
expect(await stateCount.text()).toBe('1')
})
})
\ No newline at end of file
<template>
<view class="page">
<text id="state-count" class="mb-10">state.count: {{ state.count }}</text>
<button class="increment-state-count-btn mb-10" @click="incrementStateCount">increment
state.count</button>
<view class="flex justify-between flex-row mb-10">
<text>state.count:</text>
<text id="state-count">{{ state.count }}</text>
</view>
<button
class="increment-state-count-btn mb-10"
@click="incrementStateCount">
increment state.count
</button>
<button class="update-state-btn" @click="updateState">update state</button>
</view>
</template>
<script setup>
type State = {
count: number
}
const state = shallowRef({
count: 0
} as State)
<script setup lang="uts">
type State = {
count: number
}
const incrementStateCount = () => {
state.value.count++
}
const state = shallowRef({
count: 0
} as State)
const updateState = () => {
state.value = { count: state.value.count } as State
}
</script>
\ No newline at end of file
const incrementStateCount = () => {
state.value.count++
}
const updateState = () => {
state.value = { count: state.value.count } as State
}
</script>
......@@ -147,7 +147,7 @@ function transform(fileInfo, api) {
- [x] onScopeDispose
- [x] shallowReactive
- [x] shallowReadonly
- [ ] shallowRef
- [x] shallowRef
- [ ] toRaw
- [ ] triggerRef
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册
新手
引导
客服 返回
顶部