Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
DCloud
hello-uvue
提交
6f90a7f5
H
hello-uvue
项目概览
DCloud
/
hello-uvue
通知
350
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看板
提交
6f90a7f5
编写于
1月 22, 2024
作者:
DCloud-WZF
💬
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
feat(composition api): provide and inject
上级
daec24b2
变更
5
显示空白变更内容
内联
并排
Showing
5 changed file
with
109 addition
and
9 deletion
+109
-9
pages.json
pages.json
+7
-0
pages/composition-api/dependency-injection/provide/inject.uvue
.../composition-api/dependency-injection/provide/inject.uvue
+28
-0
pages/composition-api/dependency-injection/provide/provide-inject.test.js
...n-api/dependency-injection/provide/provide-inject.test.js
+34
-0
pages/composition-api/dependency-injection/provide/provide.uvue
...composition-api/dependency-injection/provide/provide.uvue
+15
-0
pages/tab-bar/composition-api.uvue
pages/tab-bar/composition-api.uvue
+25
-9
未找到文件。
pages.json
浏览文件 @
6f90a7f5
...
@@ -601,6 +601,13 @@
...
@@ -601,6 +601,13 @@
{
{
"navigationBarTitleText"
:
"组件生命周期"
"navigationBarTitleText"
:
"组件生命周期"
}
}
},
{
"path"
:
"pages/composition-api/dependency-injection/provide/provide"
,
"style"
:
{
"navigationBarTitleText"
:
"依赖注入"
}
}
}
],
],
"tabBar"
:
{
"tabBar"
:
{
...
...
pages/composition-api/dependency-injection/provide/inject.uvue
0 → 100644
浏览文件 @
6f90a7f5
<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: {{obj}}</text>
<text class="uni-common-mt arr">arr: {{arr}}</text>
<text class="uni-common-mt fn">fn: {{(fn as () => string)()}}</text>
<text class="uni-common-mt has-injection-context">hasInjectionContext:
{{checkHasInjectionContextRes}}</text>
<button class="uni-common-mt check-has-injection-context-btn" @click="checkHasInjectionContext">check hasInjectionContext</button>
</view>
</template>
<script setup>
const msg = inject('msg')
const num = inject('num')
const obj = inject('obj')
const arr = inject('arr')
const fn = inject('fn')
const checkHasInjectionContextRes = ref('')
const checkHasInjectionContext = () => {
checkHasInjectionContextRes.value = `${hasInjectionContext()}`
}
checkHasInjectionContext()
</script>
\ No newline at end of file
pages/composition-api/dependency-injection/provide/provide-inject.test.js
0 → 100644
浏览文件 @
6f90a7f5
const
PAGE_PATH
=
'
/pages/composition-api/dependency-injection/provide/provide
'
describe
(
'
provide-inject-hasInjectionContext
'
,
()
=>
{
let
page
=
null
beforeAll
(
async
()
=>
{
page
=
await
program
.
reLaunch
(
PAGE_PATH
)
await
page
.
waitFor
(
'
view
'
)
})
it
(
'
baisc
'
,
async
()
=>
{
const
msg
=
await
page
.
$
(
'
.msg
'
)
expect
(
await
msg
.
text
()).
toBe
(
'
msg: hello
'
)
const
num
=
await
page
.
$
(
'
.num
'
)
expect
(
await
num
.
text
()).
toBe
(
'
num: 0
'
)
const
obj
=
await
page
.
$
(
'
.obj
'
)
expect
(
await
obj
.
text
()).
toBe
(
'
obj: {"a":1}
'
)
const
arr
=
await
page
.
$
(
'
.arr
'
)
expect
(
await
arr
.
text
()).
toBe
(
'
arr: [1,2,3]
'
)
const
fn
=
await
page
.
$
(
'
.fn
'
)
expect
(
await
fn
.
text
()).
toBe
(
'
fn: hello
'
)
const
hasInjectionContext
=
await
page
.
$
(
'
.has-injection-context
'
)
expect
(
await
hasInjectionContext
.
text
()).
toBe
(
'
hasInjectionContext: true
'
)
const
checkHasInjectionContextBtn
=
await
page
.
$
(
'
.check-has-injection-context-btn
'
)
await
checkHasInjectionContextBtn
.
tap
()
expect
(
await
hasInjectionContext
.
text
()).
toBe
(
'
hasInjectionContext: false
'
)
})
})
\ No newline at end of file
pages/composition-api/dependency-injection/provide/provide.uvue
0 → 100644
浏览文件 @
6f90a7f5
<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/tab-bar/composition-api.uvue
浏览文件 @
6f90a7f5
...
@@ -335,6 +335,22 @@
...
@@ -335,6 +335,22 @@
enable: true,
enable: true,
},
},
]
]
}, {
id: 'dependency-injection',
name: '依赖注入',
open: false,
pages: [
{
name: 'provide',
url: 'provide',
// #ifdef APP
enable: true,
// #endif
// #ifdef WEB
enable: false,
// #endif
}
]
}
}
] as PageList[]
] as PageList[]
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录