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

refactor(reactivity): triggerRef

上级 f1e74d1e
......@@ -622,6 +622,11 @@ export default {
name: 'toRaw',
url: 'to-raw/to-raw'
},
{
id: 'trigger-ref',
name: 'triggerRef',
url: 'trigger-ref/trigger-ref'
},
]
}
] as Page[]
......
const PAGE_PATH = '/pages/composition-api/reactivity/trigger-ref/trigger-ref'
const PAGE_PATH = '/pages/reactivity/advanced/trigger-ref/trigger-ref'
describe('triggerRef', () => {
let page = null
......@@ -8,16 +8,16 @@ describe('triggerRef', () => {
})
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 triggerRefStateBtn = await page.$('#trigger-ref-state-btn')
await triggerRefStateBtn.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 id="increment-state-count-btn" class="mb-10" @click="incrementStateCount">increment
state.count</button>
<button id="trigger-ref-state-btn" @click="triggerRefState">trigger state</button>
<view class="flex justify-between flex-row mb-10">
<text>state.count:</text>
<text id="state-count">{{ state.count }}</text>
</view>
<button
id="increment-state-count-btn"
class="mb-10"
@click="incrementStateCount">
increment state.count
</button>
<button id="trigger-ref-state-btn" @click="triggerRefState">
trigger 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 state = shallowRef({
count: 0
} as State)
const incrementStateCount = () => {
state.value.count++
}
const incrementStateCount = () => {
state.value.count++
}
const triggerRefState = () => {
triggerRef(state)
}
</script>
\ No newline at end of file
const triggerRefState = () => {
triggerRef(state)
}
</script>
......@@ -149,7 +149,7 @@ function transform(fileInfo, api) {
- [x] shallowReadonly
- [x] shallowRef
- [x] toRaw
- [ ] triggerRef
- [x] triggerRef
## directives
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册