From 1e473853469470e3d6eae50574ea6d4243fce987 Mon Sep 17 00:00:00 2001 From: shutao Date: Mon, 29 Jul 2024 19:47:31 +0800 Subject: [PATCH] update unielement.md --- docs/dom/unielement.md | 31 +++++++++++++++++++++++++++++-- 1 file changed, 29 insertions(+), 2 deletions(-) diff --git a/docs/dom/unielement.md b/docs/dom/unielement.md index 9cfc7990..6b09f7f8 100644 --- a/docs/dom/unielement.md +++ b/docs/dom/unielement.md @@ -122,7 +122,16 @@ app平台 getAttribute 不支持获取 class、style 属性, uvue/vue 页面 - + + +```uts +//通过elementId 获取到UniElement对象 +const element = uni.getElementById(elementId) +//getElementById不设置泛型,获取到安卓View +if(element != null) { + const view = element.getAndroidView() +} +``` @@ -134,7 +143,25 @@ app平台 getAttribute 不支持获取 class、style 属性, uvue/vue 页面 - + + +```uts +//通过elementId 获取web-view便签的UniElement对象 +const element = uni.getElementById(elementId) +//getElementById设置泛型为安卓底层WebView对象, 直接获取WebView 如果泛型不匹配会返回null +if(element != null) { + const webview = element.getAndroidView() +} +``` + +#### 可通过getAndroidView泛型明确定义View类型的组件 + +| 组件 | android平台原生View类型 | +| --------- | ------------------------------ | +| [view](https://doc.dcloud.net.cn/uni-app-x/component/view.html) | [ViewGroup](https://developer.android.google.cn/reference/android/view/ViewGroup) | +| [input](https://doc.dcloud.net.cn/uni-app-x/component/input.html) | [EditText](https://developer.android.google.cn/reference/android/widget/EditText) | +| [textarea](https://doc.dcloud.net.cn/uni-app-x/component/textarea.html) | [EditText](https://developer.android.google.cn/reference/android/widget/EditText) | +| [web-view](https://doc.dcloud.net.cn/uni-app-x/component/web-view.html) | [WebView](https://developer.android.google.cn/reference/android/webkit/WebView) | -- GitLab