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

refactor(component instance): defineExpose

上级 175b3a26
<script setup>
<script setup lang='uts'>
const str = 'foo str'
const num = ref(0)
const increment = () => {
......@@ -11,4 +11,4 @@
increment
})
</script>
</script>
......@@ -449,6 +449,13 @@
"navigationBarTitleText": "setup()"
}
},
{
"path": "pages/component-instance/define-expose/define-expose",
"style": {
"navigationBarTitleText": "defineExpose"
}
},
{
"path": "pages/component-instance/circular-reference/circular-reference",
......@@ -604,12 +611,6 @@
"navigationBarTitleText": "defineEmits"
}
},
{
"path": "pages/composition-api/basic/define-expose/define-expose",
"style": {
"navigationBarTitleText": "defineExpose"
}
},
{
"path": "pages/composition-api/basic/define-model/define-model",
"style": {
......
const PAGE_PATH = '/pages/composition-api/basic/define-expose/define-expose'
const PAGE_PATH = '/pages/component-instance/define-expose/define-expose'
describe('defineExpose', () => {
let page = null
beforeAll(async () => {
page = await program.reLaunch(PAGE_PATH)
await page.waitFor('view')
})
it('basic', async () => {
const fooStr = await page.$('#foo-str')
expect(await fooStr.text()).toBe('str from component Foo: foo str')
expect(await fooStr.text()).toBe('foo str')
const fooNum = await page.$('#foo-num')
expect(await fooNum.text()).toBe('num from component Foo: 0')
expect(await fooNum.text()).toBe('0')
const incrementBtn = await page.$('.increment-btn')
await incrementBtn.tap()
expect(await fooNum.text()).toBe('num from component Foo: 1')
expect(await fooNum.text()).toBe('1')
})
})
\ No newline at end of file
<template>
<view class="page">
<define-expose-foo ref="fooRef" />
<view class="flex justify-between flex-row mt-10">
<text>str from component Foo: </text>
<text id="foo-str">{{ fooStr }}</text>
</view>
<view class="flex justify-between flex-row mt-10">
<text>num from component Foo: </text>
<text id="foo-num">{{ fooNum }}</text>
</view>
<button class="increment-btn mt-10" @click="increment">
trigger Foo increment
</button>
</view>
</template>
<script setup lang="uts">
const fooRef = ref<DefineExposeFooComponentPublicInstance | null>(null)
const fooStr = ref('')
const fooNum = ref<number>(0)
onMounted(() => {
fooStr.value = fooRef.value!.str
fooNum.value = fooRef.value!.num
})
const increment = () => {
fooRef.value!.increment()
fooNum.value = fooRef.value!.num
}
</script>
<template>
<view class="page">
<define-expose-foo ref='fooRef' />
<text id="foo-str" class="uni-common-mt">str from component Foo: {{fooStr}}</text>
<text id="foo-num" class="uni-common-mt">num from component Foo: {{fooNum}}</text>
<button class="increment-btn uni-panel-h-on" @click="increment">trigger Foo increment</button>
</view>
</template>
<script setup>
const fooRef = ref<DefineExposeFooComponentPublicInstance | null>(null)
const fooStr = ref('')
const fooNum = ref<number>(0)
onMounted(() => {
fooStr.value = fooRef.value!.str
fooNum.value = fooRef.value!.num
})
const increment = () => {
fooRef.value!.increment()
fooNum.value = fooRef.value!.num
}
</script>
......@@ -373,6 +373,11 @@ export default {
id: 'setup-function',
name: 'setup()',
url: 'setup-function/setup-function'
},
{
id: 'define-expose',
name: 'defineExpose',
url: 'define-expose/define-expose'
}
] as Page[]
},
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册