提交 6016990c 编写于 作者: DCloud-WZF's avatar DCloud-WZF 💬

feat(API): getElementById

上级 ab56e4e2
...@@ -270,6 +270,12 @@ ...@@ -270,6 +270,12 @@
"enablePullDownRefresh": true "enablePullDownRefresh": true
} }
}, },
{
"path": "pages/API/get-element-by-id/get-element-by-id",
"style": {
"navigationBarTitleText": "获取节点"
}
},
{ {
"path": "pages/API/nodes-info/nodes-info", "path": "pages/API/nodes-info/nodes-info",
"style": { "style": {
......
const PAGE_PATH = "/pages/API/get-element-by-id/get-element-by-id";
let page;
describe("getElementById", () => {
beforeAll(async () => {
page = await program.navigateTo(PAGE_PATH);
await page.waitFor(1000);
});
it("getElementByNotExistId", async () => {
const res = await page.callMethod("getElementByNotExistId");
expect(!!res).toBe(false);
});
it("changeStyle", async () => {
await page.callMethod("changePageHeadBackgroundColor");
await page.callMethod("changeTextColor");
await page.callMethod("changeViewStyle");
const image = await program.screenshot();
expect(image).toMatchImageSnapshot();
});
});
<template>
<view>
<page-head id="page-head" title="getElementById"></page-head>
<view class="uni-padding-wrap">
<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>
</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('view')!
view.style.setProperty('width', '90%')
view.style.setProperty('height', '50px')
view.style.setProperty('backgroundColor', '#007AFF')
}
}
}
</script>
<template> <template>
<view> <view>
<page-head title="getLaunchOptionsSync"></page-head> <page-head title="getLaunchOptionsSync"></page-head>
<view class="uni-padding-wrap">
<button @click="getLaunchOptionsSync">getLaunchOptionsSync</button> <button @click="getLaunchOptionsSync">getLaunchOptionsSync</button>
<view <view v-if="launchOptionsPath.length > 0" class="uni-common-mt">
v-if="launchOptionsPath.length > 0"
class="uni-common-pl uni-common-mt"
>
<text>应用启动路径:</text> <text>应用启动路径:</text>
<text style="margin-top: 5px">{{ launchOptionsPath }}</text> <text style="margin-top: 5px">{{ launchOptionsPath }}</text>
</view> </view>
</view> </view>
</view>
</template> </template>
<script lang="uts"> <script lang="uts">
...@@ -22,7 +21,7 @@ export default { ...@@ -22,7 +21,7 @@ export default {
} }
}, },
methods: { methods: {
getLaunchOptionsSync: function () { getLaunchOptionsSync() {
const launchOptions = uni.getLaunchOptionsSync() const launchOptions = uni.getLaunchOptionsSync()
this.launchOptionsPath = launchOptions.path this.launchOptionsPath = launchOptions.path
if (launchOptions.path == this.homePagePath) { if (launchOptions.path == this.homePagePath) {
......
...@@ -174,6 +174,11 @@ ...@@ -174,6 +174,11 @@
url: "intersection-observer", url: "intersection-observer",
enable: false enable: false
}, */ }, */
{
name: '获取节点',
url: 'get-element-by-id',
api: ["getElementById"]
},
{ {
name: '节点信息', name: '节点信息',
url: 'nodes-info', url: 'nodes-info',
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册