提交 ba25eab3 编写于 作者: D DCloud_LXH

refactor(component-instance): emit

上级 b41b9a01
...@@ -126,13 +126,13 @@ ...@@ -126,13 +126,13 @@
{ {
"path": "pages/built-in/component/keep-alive/keep-alive-options", "path": "pages/built-in/component/keep-alive/keep-alive-options",
"style": { "style": {
"navigationBarTitleText": "keep-alive(选项式 API)" "navigationBarTitleText": "keep-alive 选项式 API"
} }
}, },
{ {
"path": "pages/built-in/component/keep-alive/keep-alive-composition", "path": "pages/built-in/component/keep-alive/keep-alive-composition",
"style": { "style": {
"navigationBarTitleText": "keep-alive(组合式 API)" "navigationBarTitleText": "keep-alive 组合式 API"
} }
}, },
{ {
...@@ -280,14 +280,14 @@ ...@@ -280,14 +280,14 @@
{ {
"path": "pages/lifecycle/page/page-composition", "path": "pages/lifecycle/page/page-composition",
"style": { "style": {
"navigationBarTitleText": "page-lifecycle(组合式 API)", "navigationBarTitleText": "page-lifecycle 组合式 API",
"enablePullDownRefresh": true "enablePullDownRefresh": true
} }
}, },
{ {
"path": "pages/lifecycle/page/page-options", "path": "pages/lifecycle/page/page-options",
"style": { "style": {
"navigationBarTitleText": "page-lifecycle(选项式 API)", "navigationBarTitleText": "page-lifecycle 选项式 API",
"enablePullDownRefresh": true "enablePullDownRefresh": true
} }
}, },
...@@ -312,13 +312,13 @@ ...@@ -312,13 +312,13 @@
{ {
"path": "pages/component-instance/refs/refs-options", "path": "pages/component-instance/refs/refs-options",
"style": { "style": {
"navigationBarTitleText": "$refs(选项式 API)" "navigationBarTitleText": "$refs 选项式 API"
} }
}, },
{ {
"path": "pages/component-instance/refs/refs-composition", "path": "pages/component-instance/refs/refs-composition",
"style": { "style": {
"navigationBarTitleText": "$refs(组合式 API)" "navigationBarTitleText": "$refs 组合式 API"
} }
}, },
{ {
...@@ -334,9 +334,15 @@ ...@@ -334,9 +334,15 @@
} }
}, },
{ {
"path": "pages/component-instance/emit-function/emit-function", "path": "pages/component-instance/emit-function/emit-function-options",
"style": { "style": {
"navigationBarTitleText": "$emit()" "navigationBarTitleText": "$emit() 选项式 API"
}
},
{
"path": "pages/component-instance/emit-function/emit-function-composition",
"style": {
"navigationBarTitleText": "defineEmits 组合式 API"
} }
}, },
{ {
...@@ -414,37 +420,37 @@ ...@@ -414,37 +420,37 @@
{ {
"path": "pages/built-in/component/slots/slots-composition", "path": "pages/built-in/component/slots/slots-composition",
"style": { "style": {
"navigationBarTitleText": "slots(组合式 API)" "navigationBarTitleText": "slots 组合式 API"
} }
}, },
{ {
"path": "pages/built-in/component/slots/slots-options", "path": "pages/built-in/component/slots/slots-options",
"style": { "style": {
"navigationBarTitleText": "slots(选项式 API)" "navigationBarTitleText": "slots 选项式 API"
} }
}, },
{ {
"path": "pages/built-in/component/template/template-options", "path": "pages/built-in/component/template/template-options",
"style": { "style": {
"navigationBarTitleText": "template(选项式 API)" "navigationBarTitleText": "template 选项式 API"
} }
}, },
{ {
"path": "pages/built-in/component/template/template-composition", "path": "pages/built-in/component/template/template-composition",
"style": { "style": {
"navigationBarTitleText": "template(组合式 API)" "navigationBarTitleText": "template 组合式 API"
} }
}, },
{ {
"path": "pages/built-in/component/template/template-map-style-options", "path": "pages/built-in/component/template/template-map-style-options",
"style": { "style": {
"navigationBarTitleText": "template-map-style(选项式 API)" "navigationBarTitleText": "template-map-style 选项式 API"
} }
}, },
{ {
"path": "pages/built-in/component/template/template-map-style-composition", "path": "pages/built-in/component/template/template-map-style-composition",
"style": { "style": {
"navigationBarTitleText": "template-map-style(组合式 API)" "navigationBarTitleText": "template-map-style 组合式 API"
} }
}, },
{ {
...@@ -456,13 +462,13 @@ ...@@ -456,13 +462,13 @@
{ {
"path": "pages/built-in/component/component/component-options", "path": "pages/built-in/component/component/component-options",
"style": { "style": {
"navigationBarTitleText": "component(选项式 API)" "navigationBarTitleText": "component 选项式 API"
} }
}, },
{ {
"path": "pages/built-in/component/component/component-composition", "path": "pages/built-in/component/component/component-composition",
"style": { "style": {
"navigationBarTitleText": "component(组合式 API)" "navigationBarTitleText": "component 组合式 API"
} }
}, },
{ {
...@@ -520,25 +526,25 @@ ...@@ -520,25 +526,25 @@
{ {
"path": "pages/examples/nested-component-communication/nested-component-communication-options", "path": "pages/examples/nested-component-communication/nested-component-communication-options",
"style": { "style": {
"navigationBarTitleText": "嵌套组件通信(选项式 API)" "navigationBarTitleText": "嵌套组件通信 选项式 API"
} }
}, },
{ {
"path": "pages/examples/nested-component-communication/nested-component-communication-composition", "path": "pages/examples/nested-component-communication/nested-component-communication-composition",
"style": { "style": {
"navigationBarTitleText": "嵌套组件通信(组合式 API)" "navigationBarTitleText": "嵌套组件通信 组合式 API"
} }
}, },
{ {
"path": "pages/examples/set-custom-child-component-root-node-class/set-custom-child-component-root-node-class-options", "path": "pages/examples/set-custom-child-component-root-node-class/set-custom-child-component-root-node-class-options",
"style": { "style": {
"navigationBarTitleText": "自定义组件中使用 class 定制另一个自定义组件根节点样式(选项式 API)" "navigationBarTitleText": "自定义组件中使用 class 定制另一个自定义组件根节点样式 选项式 API"
} }
}, },
{ {
"path": "pages/examples/set-custom-child-component-root-node-class/set-custom-child-component-root-node-class-composition", "path": "pages/examples/set-custom-child-component-root-node-class/set-custom-child-component-root-node-class-composition",
"style": { "style": {
"navigationBarTitleText": "自定义组件中使用 class 定制另一个自定义组件根节点样式(组合式 API)" "navigationBarTitleText": "自定义组件中使用 class 定制另一个自定义组件根节点样式 组合式 API"
} }
}, },
{ {
...@@ -770,14 +776,14 @@ ...@@ -770,14 +776,14 @@
{ {
"path": "pages/built-in/component/teleport/teleport-options", "path": "pages/built-in/component/teleport/teleport-options",
"style": { "style": {
"navigationBarTitleText": "teleport(选项式 API)", "navigationBarTitleText": "teleport 选项式 API",
"enablePullDownRefresh": false "enablePullDownRefresh": false
} }
}, },
{ {
"path": "pages/built-in/component/teleport/teleport-composition", "path": "pages/built-in/component/teleport/teleport-composition",
"style": { "style": {
"navigationBarTitleText": "teleport(组合式 API)", "navigationBarTitleText": "teleport 组合式 API",
"enablePullDownRefresh": false "enablePullDownRefresh": false
} }
}, },
......
<template>
<view>
<button @click="click" class="call-parent-btn">调用父组件事件</button>
</view>
</template>
<script setup lang="uts">
const emit = defineEmits(['callback'])
const click = () => {
emit('callback', `${Date.now()}`)
}
defineExpose({
click
})
</script>
\ No newline at end of file
<template>
<view class="page">
<view class="row">
<text>子组件传的参数</text>
<text>
{{ value }}
</text>
</view>
<child @callback="callback"></child>
</view>
</template>
<script setup lang="uts">
import child from './child-composition.uvue'
defineOptions({
data() {
return {
value: ''
}
},
methods: {
callback(str: string) {
this.value = str
}
}
})
</script>
<style>
.row {
display: flex;
flex-direction: row;
justify-content: space-between;
margin-bottom: 10px;
}
</style>
\ No newline at end of file
...@@ -11,7 +11,7 @@ ...@@ -11,7 +11,7 @@
</template> </template>
<script> <script>
import child from './child.uvue' import child from './child-options.uvue'
export default { export default {
components: { components: {
......
const PAGE_PATH = '/pages/component-instance/emit-function/emit-function' const PAGE_PATH = '/pages/component-instance/emit-function/emit-function-options'
const PAGE_COMPOSITION_PATH = '/pages/component-instance/emit-function/emit-function-composition'
describe('$emit()', () => { describe('$emit()', () => {
let page let page
beforeAll(async () => { it('$emit() 选项式 API 事件生效', async () => {
page = await program.reLaunch(PAGE_PATH) page = await program.reLaunch(PAGE_PATH)
await page.waitFor(500) await page.waitFor(500)
const beforeValue = await page.data('value')
const btn = await page.$('.call-parent-btn')
btn.tap()
const afterValue = await page.data('value')
expect(beforeValue).not.toBe(afterValue)
}) })
it('$emit() 事件生效', async () => { it('$emit() 组合式 API 事件生效', async () => {
page = await program.reLaunch(PAGE_COMPOSITION_PATH)
await page.waitFor(500)
const beforeValue = await page.data('value') const beforeValue = await page.data('value')
const btn = await page.$('.call-parent-btn') const btn = await page.$('.call-parent-btn')
......
<template>
<view class="page">
<view class="split-title">$forceUpdate</view>
<text class="uni-common-mt time">Date.now(): {{ Date.now() }}</text>
<button class="uni-common-mt trigger-force-update-btn" type="primary" @click="triggerForceUpdate">trigger $forceUpdate</button>
</view>
</template>
<script setup lang="uts">
const instance = getCurrentInstance()
const triggerForceUpdate = () => {
instance.$.forceUpdate()
}
defineExpose({
triggerForceUpdate
})
</script>
...@@ -248,6 +248,22 @@ export default { ...@@ -248,6 +248,22 @@ export default {
url: 'refs-composition' url: 'refs-composition'
} }
] ]
},
{
id: 'emit-function',
name: '$emit',
children: [
{
id: 'emit-options',
name: '$emit 选项式 API',
url: 'emit-function-options'
},
{
id: 'emit-composition',
name: 'defineEmits 组合式 API',
url: 'emit-function-options'
}
]
} }
] as Page[] ] as Page[]
}, },
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册