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

fix: 调整 provide 错误示例

上级 caa20390
<template> <template>
<view> <view>
<text class="uni-common-mt bold">component for inject 1</text> <text class="uni-common-mt bold">component for inject 1</text>
<text class="uni-common-mt provide-page-title"
>providePageTitle: {{ providePageTitle }}</text
>
<text class="uni-common-mt alias-provide-page-title" <text class="uni-common-mt alias-provide-page-title"
>aliasProvidePageTitle: {{ aliasProvidePageTitle }}</text >aliasProvidePageTitle: {{ aliasProvidePageTitle }}</text
> >
<text class="uni-common-mt computed-title"
>computedTitle: {{ computedTitle }}</text
>
<text class="uni-common-mt provide-data-obj-title"
>provideDataObj.title: {{ provideDataObj['title'] }}</text
>
<text class="uni-common-mt provide-data-obj-content"
>provideDataObj.content: {{ provideDataObj['content'] }}</text
>
<text class="uni-common-mt provide-page-str" <text class="uni-common-mt provide-page-str"
>providePageStr: {{ providePageStr }}</text >providePageStr: {{ providePageStr }}</text
> >
...@@ -57,22 +45,11 @@ ...@@ -57,22 +45,11 @@
<script lang="uts"> <script lang="uts">
export default { export default {
inject: { inject: {
providePageTitle: {
type: String,
default: 'default provide page title'
},
aliasProvidePageTitle: { aliasProvidePageTitle: {
type: String, type: String,
from: 'providePageTitle', from: 'providePageTitle',
default: 'default alias provide page title' default: 'default alias provide page title'
}, },
computedTitle: {
type: String,
default: 'default computed title'
},
provideDataObj: {
type: Object as PropType<UTSJSONObject>,
},
providePageStr: { providePageStr: {
type: String, type: String,
default: 'default provide page str' default: 'default provide page str'
......
...@@ -6,49 +6,11 @@ describe('字面量方式创建 provide', () => { ...@@ -6,49 +6,11 @@ describe('字面量方式创建 provide', () => {
page = await program.reLaunch(PAGE_PATH) page = await program.reLaunch(PAGE_PATH)
await page.waitFor('view') await page.waitFor('view')
}) })
it('variable', async () => {
const providePageTitleEl = await page.$('.provide-page-title')
const providePageTitleText = await providePageTitleEl.text()
expect(providePageTitleText).toBe(
'providePageTitle: 字面量方式定义 provide page title'
)
})
it('alias', async () => { it('alias', async () => {
const aliasProvidePageTitleEl = await page.$('.alias-provide-page-title') const aliasProvidePageTitleEl = await page.$('.alias-provide-page-title')
const aliasProvidePageTitleText = await aliasProvidePageTitleEl.text() const aliasProvidePageTitleText = await aliasProvidePageTitleEl.text()
expect(aliasProvidePageTitleText).toBe( expect(aliasProvidePageTitleText).toBe(
'aliasProvidePageTitle: 字面量方式定义 provide page title' 'aliasProvidePageTitle: default alias provide page title'
)
})
it('reactive data', async () => {
const computedTitleEl = await page.$('.computed-title')
let computedTitleText = await computedTitleEl.text()
expect(computedTitleText).toBe(
'computedTitle: 字面量方式定义 provide page title'
)
const provideDataObjTitleEl = await page.$('.provide-data-obj-title')
let provideDataObjTitleText = await provideDataObjTitleEl.text()
expect(provideDataObjTitleText).toBe(
'provideDataObj.title: data obj.title'
)
const provideDataObjContentEl = await page.$('.provide-data-obj-content')
let provideDataObjContentText = await provideDataObjContentEl.text()
expect(provideDataObjContentText).toBe(
'provideDataObj.content: data obj.content'
)
const changeDataBtn = await page.$('.change-data-btn')
await changeDataBtn.tap()
computedTitleText = await computedTitleEl.text()
expect(computedTitleText).toBe(
'computedTitle: 字面量方式定义 provide page title changed'
)
provideDataObjTitleText = await provideDataObjTitleEl.text()
expect(provideDataObjTitleText).toBe('provideDataObj.title: new title')
provideDataObjContentText = await provideDataObjContentEl.text()
expect(provideDataObjContentText).toBe(
'provideDataObj.content: new content'
) )
}) })
it('string', async () => { it('string', async () => {
......
...@@ -7,7 +7,6 @@ ...@@ -7,7 +7,6 @@
<button class="uni-common-mt" @click="goProvidePage2"> <button class="uni-common-mt" @click="goProvidePage2">
跳转函数方式定义 provide 示例 跳转函数方式定义 provide 示例
</button> </button>
<button class="uni-common-mt change-data-btn" @click="changeData">change data</button>
<ComponentForInject /> <ComponentForInject />
</view> </view>
<!-- #ifdef APP --> <!-- #ifdef APP -->
...@@ -33,9 +32,6 @@ export default { ...@@ -33,9 +32,6 @@ export default {
} }
}, },
provide: { provide: {
providePageTitle: this.title,
computedTitle: computed<string>((): string => this.title),
provideDataObj: this.obj,
providePageStr: '字面量方式定义 provide page str', providePageStr: '字面量方式定义 provide page str',
providePageNum: 1, providePageNum: 1,
providePageBool: true, providePageBool: true,
...@@ -52,11 +48,6 @@ export default { ...@@ -52,11 +48,6 @@ export default {
uni.navigateTo({ uni.navigateTo({
url: '/pages/composition/provide/provide-page2' url: '/pages/composition/provide/provide-page2'
}) })
},
changeData() {
this.title = '字面量方式定义 provide page title changed'
this.obj['title'] = 'new title'
this.obj['content'] = 'new content'
} }
}, },
} }
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册