Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
OpenHarmony
Docs
提交
b1f9843a
D
Docs
项目概览
OpenHarmony
/
Docs
大约 1 年 前同步成功
通知
159
Star
292
Fork
28
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
D
Docs
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
未验证
提交
b1f9843a
编写于
2月 22, 2023
作者:
O
openharmony_ci
提交者:
Gitee
2月 22, 2023
浏览文件
操作
浏览文件
下载
差异文件
!14921 【Monthly】翻译完成 14227
Merge pull request !14921 from ester.zhou/cherry-pick-1676943606
上级
8d8dda6b
39879ba6
变更
1
隐藏空白更改
内联
并排
Showing
1 changed file
with
46 addition
and
10 deletion
+46
-10
en/application-dev/ui/ui-ts-components-web.md
en/application-dev/ui/ui-ts-components-web.md
+46
-10
未找到文件。
en/application-dev/ui/ui-ts-components-web.md
浏览文件 @
b1f9843a
...
...
@@ -8,10 +8,12 @@ Create a **\<Web>** component in the .ets file under **main/ets/MainAbility/page
```
ts
// xxx.ets
import
web_webview
from
'
@ohos.web.webview
'
;
@
Entry
@
Component
struct
WebComponent
{
controller
:
WebController
=
new
Web
Controller
();
controller
:
web_webview
.
WebviewController
=
new
web_webview
.
Webview
Controller
();
build
()
{
Column
()
{
Web
({
src
:
'
https://www.example.com
'
,
controller
:
this
.
controller
})
...
...
@@ -26,11 +28,13 @@ When using the **\<Web>** component, you must specify the styles and attributes.
```
ts
// xxx.ets
import
web_webview
from
'
@ohos.web.webview
'
;
@
Entry
@
Component
struct
WebComponent
{
fileAccess
:
boolean
=
true
;
controller
:
WebController
=
new
Web
Controller
();
controller
:
web_webview
.
WebviewController
=
new
web_webview
.
Webview
Controller
();
build
()
{
Column
()
{
Text
(
'
Hello world!
'
)
...
...
@@ -54,13 +58,15 @@ Add the **onProgressChange** event for the **\<Web>** component, which is trigge
```
ts
// xxx.ets
import
web_webview
from
'
@ohos.web.webview
'
;
@
Entry
@
Component
struct
WebComponent
{
@
State
progress
:
number
=
0
;
@
State
hideProgress
:
boolean
=
true
;
fileAccess
:
boolean
=
true
;
controller
:
WebController
=
new
Web
Controller
();
controller
:
web_webview
.
WebviewController
=
new
web_webview
.
Webview
Controller
();
build
()
{
Column
()
{
Text
(
'
Hello world!
'
)
...
...
@@ -93,14 +99,17 @@ Add the **runJavaScript** method to the **onPageEnd** event. The **onPageEnd** e
```
ts
// xxx.ets
import
web_webview
from
'
@ohos.web.webview
'
;
@
Entry
@
Component
struct
WebComponent
{
@
State
progress
:
number
=
0
;
@
State
hideProgress
:
boolean
=
true
;
@
State
webResult
:
string
=
''
fileAccess
:
boolean
=
true
;
// Define the controller for the \<Web> component.
controller
:
WebController
=
new
Web
Controller
();
controller
:
web_webview
.
WebviewController
=
new
web_webview
.
Webview
Controller
();
build
()
{
Column
()
{
Text
(
'
Hello world!
'
)
...
...
@@ -124,8 +133,23 @@ struct WebComponent {
})
.
onPageEnd
(
e
=>
{
// test() is defined in index.html.
this
.
controller
.
runJavaScript
({
script
:
'
test()
'
});
console
.
info
(
'
url:
'
,
e
.
url
);
try
{
this
.
controller
.
runJavaScript
(
'
test()
'
,
(
error
,
result
)
=>
{
if
(
error
)
{
console
.
info
(
`run JavaScript error: `
+
JSON
.
stringify
(
error
))
return
;
}
if
(
result
)
{
this
.
webResult
=
result
console
.
info
(
`The test() return value is:
${
result
}
`
)
}
});
console
.
info
(
'
url:
'
,
e
.
url
);
}
catch
(
error
)
{
console
.
error
(
`ErrorCode:
${
error
.
code
}
, Message:
${
error
.
message
}
`
);
}
})
Text
(
'
End
'
)
.
fontSize
(
20
)
...
...
@@ -160,10 +184,12 @@ The configuration procedure is as follows:
1.
Set the
**webDebuggingAccess**
attribute of the
**\<Web>**
component to
**true**
.
```
ts
// xxx.ets
import
web_webview
from
'
@ohos.web.webview
'
;
@
Entry
@
Component
struct
WebComponent
{
controller
:
WebController
=
new
WebController
()
controller
:
web_webview
.
WebviewController
=
new
web_webview
.
WebviewController
();
build
()
{
Column
()
{
Web
({
src
:
'
www.example.com
'
,
controller
:
this
.
controller
})
...
...
@@ -189,20 +215,30 @@ In this example, you'll implement a **\<Web>** component where videos can be pla
```
ts
// xxx.ets
import
web_webview
from
'
@ohos.web.webview
'
;
@
Entry
@
Component
struct
WebComponent
{
controller
:
WebController
=
new
Web
Controller
();
controller
:
web_webview
.
WebviewController
=
new
web_webview
.
Webview
Controller
();
build
()
{
Column
()
{
Row
()
{
Button
(
'
onActive
'
).
onClick
(()
=>
{
console
.
info
(
"
Web Component onActive
"
);
this
.
controller
.
onActive
();
try
{
this
.
controller
.
onActive
();
}
catch
(
error
)
{
console
.
error
(
`Errorcode:
${
error
.
code
}
, Message:
${
error
.
message
}
`
);
}
})
Button
(
'
onInactive
'
).
onClick
(()
=>
{
console
.
info
(
"
Web Component onInactive
"
);
this
.
controller
.
onInactive
();
try
{
this
.
controller
.
onInactive
();
}
catch
(
error
)
{
console
.
error
(
`Errorcode:
${
error
.
code
}
, Message:
${
error
.
message
}
`
);
}
})
}
Web
({
src
:
$rawfile
(
'
index.html
'
),
controller
:
this
.
controller
})
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录