Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
DCloud
hello-uvue
提交
beaf87d3
H
hello-uvue
项目概览
DCloud
/
hello-uvue
通知
347
Star
2
Fork
7
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
1
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
H
hello-uvue
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
1
Issue
1
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
提交
beaf87d3
编写于
4月 18, 2024
作者:
DCloud-WZF
💬
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
refactor(component instance): provide & inject
上级
d8ab7054
变更
14
显示空白变更内容
内联
并排
Showing
14 changed file
with
123 addition
and
97 deletion
+123
-97
pages.json
pages.json
+20
-24
pages/component-instance/inject/inject-composition.uvue
pages/component-instance/inject/inject-composition.uvue
+32
-0
pages/component-instance/inject/inject-options-1.uvue
pages/component-instance/inject/inject-options-1.uvue
+13
-13
pages/component-instance/inject/inject-options-2.uvue
pages/component-instance/inject/inject-options-2.uvue
+10
-10
pages/component-instance/provide/provide-composition.test.js
pages/component-instance/provide/provide-composition.test.js
+2
-2
pages/component-instance/provide/provide-composition.uvue
pages/component-instance/provide/provide-composition.uvue
+15
-0
pages/component-instance/provide/provide-options-1.test.js
pages/component-instance/provide/provide-options-1.test.js
+5
-2
pages/component-instance/provide/provide-options-1.uvue
pages/component-instance/provide/provide-options-1.uvue
+2
-3
pages/component-instance/provide/provide-options-2.test.js
pages/component-instance/provide/provide-options-2.test.js
+2
-2
pages/component-instance/provide/provide-options-2.uvue
pages/component-instance/provide/provide-options-2.uvue
+1
-1
pages/composition-api/dependency-injection/provide/provide.uvue
...composition-api/dependency-injection/provide/provide.uvue
+0
-15
pages/composition/inject/inject.test.js
pages/composition/inject/inject.test.js
+0
-13
pages/composition/inject/inject.uvue
pages/composition/inject/inject.uvue
+0
-12
pages/index/index.uvue
pages/index/index.uvue
+21
-0
未找到文件。
pages.json
浏览文件 @
beaf87d3
...
...
@@ -419,6 +419,26 @@
"navigationBarTitleText"
:
"call-method-other 组合式 API"
}
},
{
"path"
:
"pages/component-instance/provide/provide-options-1"
,
"style"
:
{
"navigationBarTitleText"
:
"provide 选项式 API 字面量"
}
},
{
"path"
:
"pages/component-instance/provide/provide-options-2"
,
"style"
:
{
"navigationBarTitleText"
:
"provide 选项式 API 函数"
}
},
{
"path"
:
"pages/component-instance/provide/provide-composition"
,
"style"
:
{
"navigationBarTitleText"
:
"provide 组合式 API"
}
},
{
"path"
:
"pages/component-instance/circular-reference/circular-reference"
,
"style"
:
{
...
...
@@ -537,24 +557,6 @@
}
},
//
#endif
{
"path"
:
"pages/composition/provide/provide"
,
"style"
:
{
"navigationBarTitleText"
:
"provide"
}
},
{
"path"
:
"pages/composition/provide/provide-page2"
,
"style"
:
{
"navigationBarTitleText"
:
"provide-page-2"
}
},
{
"path"
:
"pages/composition/inject/inject"
,
"style"
:
{
"navigationBarTitleText"
:
"inject"
}
},
{
"path"
:
"pages/composition/setup/setup"
,
"style"
:
{
...
...
@@ -791,12 +793,6 @@
"navigationBarTitleText"
:
"onScopeDispose"
}
},
{
"path"
:
"pages/composition-api/dependency-injection/provide/provide"
,
"style"
:
{
"navigationBarTitleText"
:
"依赖注入"
}
},
{
"path"
:
"pages/built-in/component/teleport/teleport-options"
,
"style"
:
{
...
...
pages/compo
sition-api/dependency-injection/provide/inject
.uvue
→
pages/compo
nent-instance/inject/inject-composition
.uvue
浏览文件 @
beaf87d3
<template>
<view>
<text>inject page</text>
<text class="
uni-common-mt
msg">msg: {{msg}}</text>
<text class="
uni-common-mt
num">num: {{num}}</text>
<text class="
uni-common-mt
obj">obj: {{JSON.stringify(obj)}}</text>
<text class="
uni-common-mt
arr">arr: {{JSON.stringify(arr)}}</text>
<text class="
uni-common-mt
fn">fn: {{(fn as () => string)()}}</text>
<text class="
uni-common-mt
has-injection-context">hasInjectionContext:
<text class="
mt-10
msg">msg: {{msg}}</text>
<text class="
mt-10
num">num: {{num}}</text>
<text class="
mt-10
obj">obj: {{JSON.stringify(obj)}}</text>
<text class="
mt-10
arr">arr: {{JSON.stringify(arr)}}</text>
<text class="
mt-10
fn">fn: {{(fn as () => string)()}}</text>
<text class="
mt-10
has-injection-context">hasInjectionContext:
{{checkHasInjectionContextRes}}</text>
<button class="uni-common-mt check-has-injection-context-btn" @click="checkHasInjectionContext">check hasInjectionContext</button>
<button class="mt-10 check-has-injection-context-btn" @click="checkHasInjectionContext">check
hasInjectionContext</button>
</view>
</template>
<script setup>
<script setup
lang='uts'
>
const msg = inject('msg')
const num = inject('num')
const obj = inject('obj')
...
...
pages/compo
sition/provide/component-for-inject
-1.uvue
→
pages/compo
nent-instance/inject/inject-options
-1.uvue
浏览文件 @
beaf87d3
<template>
<view>
<text class="
uni-common-mt
bold">component for inject 1</text>
<text class="
uni-common-mt
alias-provide-page-title"
<text class="
mt-10
bold">component for inject 1</text>
<text class="
mt-10
alias-provide-page-title"
>aliasProvidePageTitle: {{ aliasProvidePageTitle }}</text
>
<text class="
uni-common-mt
provide-page-str"
<text class="
mt-10
provide-page-str"
>providePageStr: {{ providePageStr }}</text
>
<text class="
uni-common-mt
provide-page-num"
<text class="
mt-10
provide-page-num"
>providePageNum: {{ providePageNum }}</text
>
<text class="
uni-common-mt
provide-page-bool"
<text class="
mt-10
provide-page-bool"
>providePageBool: {{ providePageBool }}</text
>
<text class="
uni-common-mt
provide-page-object-title"
<text class="
mt-10
provide-page-object-title"
>providePageObject.title: {{ providePageObject['title'] }}</text
>
<text class="
uni-common-mt
provide-page-object-content"
<text class="
mt-10
provide-page-object-content"
>providePageObject.content: {{ providePageObject['content'] }}</text
>
<text class="
uni-common-mt
provide-page-arr"
<text class="
mt-10
provide-page-arr"
>providePageArr: {{ JSON.stringify(providePageArr) }}</text
>
<text class="
uni-common-mt
provide-page-map"
<text class="
mt-10
provide-page-map"
>providePageMap: {{ JSON.stringify(providePageMapObj) }}</text
>
<text class="
uni-common-mt
provide-page-set"
<text class="
mt-10
provide-page-set"
>providePageSet: {{ JSON.stringify(providePageSetArr) }}</text
>
<text class="
uni-common-mt
test-inject-string-default-value"
<text class="
mt-10
test-inject-string-default-value"
>testInjectStringDefaultValue: {{ testInjectStringDefaultValue }}</text
>
<text class="
uni-common-mt
test-inject-object-default-value-title"
<text class="
mt-10
test-inject-object-default-value-title"
>testInjectObjectDefaultValue.title:
{{ testInjectObjectDefaultValue['title'] }}</text
>
<text class="
uni-common-mt
test-inject-object-default-value-content"
<text class="
mt-10
test-inject-object-default-value-content"
>testInjectObjectDefaultValue.content:
{{ testInjectObjectDefaultValue['content'] }}</text
>
...
...
pages/compo
sition/provide/component-for-inject
-2.uvue
→
pages/compo
nent-instance/inject/inject-options
-2.uvue
浏览文件 @
beaf87d3
<template>
<view>
<text class="
uni-common-mt
bold">component for inject 2</text>
<text class="
uni-common-mt
provide-page-title"
<text class="
mt-10
bold">component for inject 2</text>
<text class="
mt-10
provide-page-title"
>providePageTitle: {{ providePageTitle }}</text
>
<text class="
uni-common-mt
provide-page-str">providePageStr: {{ providePageStr }}</text>
<text class="
uni-common-mt
provide-page-num">providePageNum: {{ providePageNum }}</text>
<text class="
uni-common-mt
provide-page-bool">providePageBool: {{ providePageBool }}</text>
<text class="
uni-common-mt
provide-page-object-title"
<text class="
mt-10
provide-page-str">providePageStr: {{ providePageStr }}</text>
<text class="
mt-10
provide-page-num">providePageNum: {{ providePageNum }}</text>
<text class="
mt-10
provide-page-bool">providePageBool: {{ providePageBool }}</text>
<text class="
mt-10
provide-page-object-title"
>providePageObject.title: {{ providePageObject['title'] }}</text
>
<text class="
uni-common-mt
provide-page-object-content"
<text class="
mt-10
provide-page-object-content"
>providePageObject.content: {{ providePageObject['content'] }}</text
>
<text class="
uni-common-mt
provide-page-arr">providePageArr: {{ JSON.stringify(providePageArr) }}</text>
<text class="
uni-common-mt
provide-page-map">providePageMap: {{ JSON.stringify(providePageMapObj) }}</text>
<text class="
uni-common-mt
provide-page-set">providePageSet: {{ JSON.stringify(providePageSetArr) }}</text>
<text class="
mt-10
provide-page-arr">providePageArr: {{ JSON.stringify(providePageArr) }}</text>
<text class="
mt-10
provide-page-map">providePageMap: {{ JSON.stringify(providePageMapObj) }}</text>
<text class="
mt-10
provide-page-set">providePageSet: {{ JSON.stringify(providePageSetArr) }}</text>
</view>
</template>
...
...
pages/compo
sition-api/dependency-injection/provide/provide-inject
.test.js
→
pages/compo
nent-instance/provide/provide-composition
.test.js
浏览文件 @
beaf87d3
const
PAGE_PATH
=
'
/pages/compo
sition-api/dependency-injection/provide/provide
'
const
PAGE_PATH
=
'
/pages/compo
nent-instance/provide/provide-composition
'
describe
(
'
provide-inject-hasInjectionContext
'
,
()
=>
{
describe
(
'
组合式 API provide
'
,
()
=>
{
let
page
=
null
beforeAll
(
async
()
=>
{
page
=
await
program
.
reLaunch
(
PAGE_PATH
)
...
...
pages/component-instance/provide/provide-composition.uvue
0 → 100644
浏览文件 @
beaf87d3
<template>
<view class="page">
<inject-comp />
</view>
</template>
<script setup lang="uts">
import InjectComp from '../inject/inject-composition.uvue';
provide('msg', 'hello');
provide('num', 0);
provide('obj', { a: 1 });
provide('arr', [1, 2, 3]);
provide('fn', () : string => 'hello');
</script>
pages/compo
sition/provide/provide
.test.js
→
pages/compo
nent-instance/provide/provide-options-1
.test.js
浏览文件 @
beaf87d3
const
PAGE_PATH
=
'
/pages/composition/provide/provide
'
describe
(
'
字面量方式创建 provide
'
,
()
=>
{
jest
.
setTimeout
(
20000
)
const
PAGE_PATH
=
'
/pages/component-instance/provide/provide-options-1
'
describe
(
'
选项式 API 字面量方式创建 provide
'
,
()
=>
{
let
page
beforeAll
(
async
()
=>
{
page
=
await
program
.
reLaunch
(
PAGE_PATH
)
...
...
pages/compo
sition/provide/provide
.uvue
→
pages/compo
nent-instance/provide/provide-options-1
.uvue
浏览文件 @
beaf87d3
...
...
@@ -4,7 +4,7 @@
<!-- #endif -->
<view class="page">
<text>provide page</text>
<button class="
uni-common-mt
" @click="goProvidePage2">
<button class="
mt-10
" @click="goProvidePage2">
跳转函数方式定义 provide 示例
</button>
<ComponentForInject />
...
...
@@ -15,8 +15,7 @@
</template>
<script lang="uts">
import { computed } from 'vue'
import ComponentForInject from './component-for-inject-1.uvue'
import ComponentForInject from '../inject/inject-options-1.uvue'
export default {
components: {
...
...
pages/compo
sition/provide/provide-page
2.test.js
→
pages/compo
nent-instance/provide/provide-options-
2.test.js
浏览文件 @
beaf87d3
const
PAGE_PATH
=
'
/pages/compo
sition/provide/provide-page
2
'
describe
(
'
函数方式创建 provide
'
,
()
=>
{
const
PAGE_PATH
=
'
/pages/compo
nent-instance/provide/provide-options-
2
'
describe
(
'
选项式 API
函数方式创建 provide
'
,
()
=>
{
let
page
beforeAll
(
async
()
=>
{
page
=
await
program
.
reLaunch
(
PAGE_PATH
)
...
...
pages/compo
sition/provide/provide-page
2.uvue
→
pages/compo
nent-instance/provide/provide-options-
2.uvue
浏览文件 @
beaf87d3
...
...
@@ -12,7 +12,7 @@
</template>
<script lang="uts">
import ComponentForInject from '.
/component-for-inject
-2.uvue'
import ComponentForInject from '.
./inject/inject-options
-2.uvue'
export default {
components: {
...
...
pages/composition-api/dependency-injection/provide/provide.uvue
已删除
100644 → 0
浏览文件 @
d8ab7054
<template>
<view class="page">
<inject-comp />
</view>
</template>
<script setup>
import InjectComp from './inject.uvue';
provide('msg', 'hello');
provide('num', 0);
provide('obj', { a: 1 });
provide('arr', [1, 2, 3]);
provide('fn', () : string => 'hello');
</script>
\ No newline at end of file
pages/composition/inject/inject.test.js
已删除
100644 → 0
浏览文件 @
d8ab7054
const
PAGE_PATH
=
'
/pages/composition/inject/inject
'
describe
(
'
inject
'
,
()
=>
{
it
(
'
basic
'
,
async
()
=>
{
const
page
=
await
program
.
reLaunch
(
PAGE_PATH
)
await
page
.
waitFor
(
'
view
'
)
const
globalProvideMsgEl
=
await
page
.
$
(
'
.global-provide-msg
'
)
const
globalProvideMsgElText
=
await
globalProvideMsgEl
.
text
()
expect
(
globalProvideMsgElText
).
toBe
(
'
globalProvideMsg: global provide message
'
)
})
})
pages/composition/inject/inject.uvue
已删除
100644 → 0
浏览文件 @
d8ab7054
<template>
<view class="page">
<text>inject page</text>
<text class="global-provide-msg">globalProvideMsg: {{globalProvideMsg}}</text>
</view>
</template>
<script lang="uts">
export default {
inject: ['globalProvideMsg'],
}
</script>
pages/index/index.uvue
浏览文件 @
beaf87d3
...
...
@@ -331,6 +331,27 @@ export default {
url: 'call-method-other-composition'
}
]
},
{
id: 'provide',
name: 'provide',
children: [
{
id: 'provide-options-1',
name: 'provide 选项式 API 字面量方式',
url: 'provide-options-1'
},
{
id: 'provide-options-2',
name: 'provide 选项式 API 函数方式',
url: 'provide-options-2'
},
{
id: 'provide-composition',
name: 'provide 组合式 API',
url: 'provide-composition'
},
]
}
] as Page[]
},
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录