Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
Accustomed_
hello uni-app x
提交
c26e1dff
H
hello uni-app x
项目概览
Accustomed_
/
hello uni-app x
与 Fork 源项目一致
Fork自
DCloud / hello uni-app x
通知
1
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
H
hello uni-app x
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
提交
c26e1dff
编写于
10月 21, 2023
作者:
DCloud-WZF
💬
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
feat: getElementById 多根节点示例及测试
上级
5820e68f
变更
5
隐藏空白更改
内联
并排
Showing
5 changed file
with
142 addition
and
55 deletion
+142
-55
pages.json
pages.json
+6
-0
pages/API/get-element-by-id/get-element-by-id-multiple-root-node.test.js
...lement-by-id/get-element-by-id-multiple-root-node.test.js
+22
-0
pages/API/get-element-by-id/get-element-by-id-multiple-root-node.uvue
...t-element-by-id/get-element-by-id-multiple-root-node.uvue
+52
-0
pages/API/get-element-by-id/get-element-by-id.test.js
pages/API/get-element-by-id/get-element-by-id.test.js
+3
-2
pages/API/get-element-by-id/get-element-by-id.uvue
pages/API/get-element-by-id/get-element-by-id.uvue
+59
-53
未找到文件。
pages.json
浏览文件 @
c26e1dff
...
@@ -307,6 +307,12 @@
...
@@ -307,6 +307,12 @@
"style"
:
{
"style"
:
{
"navigationBarTitleText"
:
"获取节点"
"navigationBarTitleText"
:
"获取节点"
}
}
},
{
"path"
:
"pages/API/get-element-by-id/get-element-by-id-multiple-root-node"
,
"style"
:
{
"navigationBarTitleText"
:
"获取节点-多根节点"
}
},
},
{
{
"path"
:
"pages/API/nodes-info/nodes-info"
,
"path"
:
"pages/API/nodes-info/nodes-info"
,
...
...
pages/API/get-element-by-id/get-element-by-id-multiple-root-node.test.js
0 → 100644
浏览文件 @
c26e1dff
const
PAGE_PATH
=
"
/pages/API/get-element-by-id/get-element-by-id-multiple-root-node
"
;
let
page
;
describe
(
"
getElementByIdForMultipleRootNode
"
,
()
=>
{
beforeAll
(
async
()
=>
{
page
=
await
program
.
reLaunch
(
PAGE_PATH
);
await
page
.
waitFor
(
1000
);
});
it
(
"
getElementByNotExistId
"
,
async
()
=>
{
const
res
=
await
page
.
callMethod
(
"
getElementByNotExistId
"
);
expect
(
res
).
toBe
(
null
);
});
it
(
"
changeStyle
"
,
async
()
=>
{
await
page
.
callMethod
(
"
changePageHeadBackgroundColor
"
);
await
page
.
callMethod
(
"
changeTextColor
"
);
await
page
.
callMethod
(
"
changeViewStyle
"
);
await
page
.
waitFor
(
500
);
const
image
=
await
program
.
screenshot
();
expect
(
image
).
toMatchImageSnapshot
();
});
});
\ No newline at end of file
pages/API/get-element-by-id/get-element-by-id-multiple-root-node.uvue
0 → 100644
浏览文件 @
c26e1dff
<template>
<view class="uni-padding-wrap">
<page-head
id="page-head"
title="getElementById-multiple-root-node"
></page-head>
<text id="text">this is text</text>
<view id="view" class="uni-common-mt" style="border: 1px solid red"
>this is view</view
>
<button class="uni-btn" @click="changePageHeadBackgroundColor">
修改 page-head 背景色
</button>
<button class="uni-btn" @click="changeTextColor">修改 text 字体颜色</button>
<button class="uni-btn" @click="changeViewStyle">
修改 view 宽高及背景色
</button>
</view>
</template>
<script lang="uts">
export default {
data() {
return {
checked: false,
homePagePath: '/pages/tabBar/component',
launchOptionsPath: '',
}
},
methods: {
getElementByNotExistId(): Element | null {
return uni.getElementById('not-exist-id')
},
changePageHeadBackgroundColor(){
const pageHead = uni.getElementById('page-head')!
pageHead.style.setProperty('backgroundColor', 'red')
},
changeTextColor(){
const text = uni.getElementById('text')!
text.style.setProperty('color', 'red')
},
changeViewStyle(){
const view = uni.getElementById<UniViewElement>('view')
if(view !== null){
view.style.setProperty('width', '90%')
view.style.setProperty('height', '50px')
view.style.setProperty('backgroundColor', '#007AFF')
}
}
}
}
</script>
pages/API/get-element-by-id/get-element-by-id.test.js
浏览文件 @
c26e1dff
...
@@ -3,17 +3,18 @@ let page;
...
@@ -3,17 +3,18 @@ let page;
describe
(
"
getElementById
"
,
()
=>
{
describe
(
"
getElementById
"
,
()
=>
{
beforeAll
(
async
()
=>
{
beforeAll
(
async
()
=>
{
page
=
await
program
.
navigateTo
(
PAGE_PATH
);
page
=
await
program
.
reLaunch
(
PAGE_PATH
);
await
page
.
waitFor
(
1000
);
await
page
.
waitFor
(
1000
);
});
});
it
(
"
getElementByNotExistId
"
,
async
()
=>
{
it
(
"
getElementByNotExistId
"
,
async
()
=>
{
const
res
=
await
page
.
callMethod
(
"
getElementByNotExistId
"
);
const
res
=
await
page
.
callMethod
(
"
getElementByNotExistId
"
);
expect
(
!!
res
).
toBe
(
false
);
expect
(
res
).
toBe
(
null
);
});
});
it
(
"
changeStyle
"
,
async
()
=>
{
it
(
"
changeStyle
"
,
async
()
=>
{
await
page
.
callMethod
(
"
changePageHeadBackgroundColor
"
);
await
page
.
callMethod
(
"
changePageHeadBackgroundColor
"
);
await
page
.
callMethod
(
"
changeTextColor
"
);
await
page
.
callMethod
(
"
changeTextColor
"
);
await
page
.
callMethod
(
"
changeViewStyle
"
);
await
page
.
callMethod
(
"
changeViewStyle
"
);
await
page
.
waitFor
(
500
);
const
image
=
await
program
.
screenshot
();
const
image
=
await
program
.
screenshot
();
expect
(
image
).
toMatchImageSnapshot
();
expect
(
image
).
toMatchImageSnapshot
();
});
});
...
...
pages/API/get-element-by-id/get-element-by-id.uvue
浏览文件 @
c26e1dff
<template>
<template>
<view>
<view>
<page-head id="page-head" title="getElementById"></page-head>
<page-head id="page-head" title="getElementById"></page-head>
<view class="uni-padding-wrap">
<view class="uni-padding-wrap">
<text id="text">this is text</text>
<text id="text">this is text</text>
<view id="view" class="uni-common-mt" style="border: 1px solid red"
<view id="view" class="uni-common-mt" style="border: 1px solid red"
>this is view</view
>this is view</view
>
>
<button class="uni-btn" @click="changePageHeadBackgroundColor">
<button class="uni-btn" @click="changePageHeadBackgroundColor">
修改 page-head 背景色
修改 page-head 背景色
</button>
</button>
<button class="uni-btn" @click="changeTextColor">
<button class="uni-btn" @click="changeTextColor">
修改 text 字体颜色
修改 text 字体颜色
</button>
</button>
<button class="uni-btn" @click="changeViewStyle">
<button class="uni-btn" @click="changeViewStyle">
修改 view 宽高及背景色
修改 view 宽高及背景色
</button>
</button>
</view>
<button class="uni-btn" @click="goMultipleRootNode">
</view>
跳转多根节点示例
</template>
</button>
</view>
<script lang="uts">
</view>
export default {
</template>
data() {
return {
<script lang="uts">
checked: false,
export default {
homePagePath: '/pages/tabBar/component',
data() {
launchOptionsPath: '',
return {
}
checked: false,
},
homePagePath: '/pages/tabBar/component',
methods: {
launchOptionsPath: '',
getElementByNotExistId(): Element | null {
}
return uni.getElementById('not-exist-id')
},
},
methods: {
changePageHeadBackgroundColor(){
getElementByNotExistId() : Element | null {
const pageHead = uni.getElementById('page-head')!
return uni.getElementById('not-exist-id')
pageHead.style.setProperty('backgroundColor', 'red')
},
},
changePageHeadBackgroundColor() {
changeTextColor(){
const pageHead = uni.getElementById('page-head')!
const text = uni.getElementById('text')!
pageHead.style.setProperty('backgroundColor', 'red')
text.style.setProperty('color', 'red')
},
},
changeTextColor() {
changeViewStyle(){
const text = uni.getElementById('text')!
const view = uni.getElementById<UniViewElement>('view')
text.style.setProperty('color', 'red')
if(view !== null){
},
view.style.setProperty('width', '90%')
changeViewStyle() {
view.style.setProperty('height', '50px')
const view = uni.getElementById<UniViewElement>('view')
view.style.setProperty('backgroundColor', '#007AFF')
if (view !== null) {
}
view.style.setProperty('width', '90%')
}
view.style.setProperty('height', '50px')
}
view.style.setProperty('backgroundColor', '#007AFF')
}
}
</script>
},
goMultipleRootNode() {
uni.navigateTo({ url: '/pages/API/get-element-by-id/get-element-by-id-multiple-root-node' })
}
}
}
</script>
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录