HomeDocs
跳到主要内容

native-webview

简介

非同层 webview 组件,承载网页的容器。

属性说明

属性名类型必填默认值说明最低版本
srcstringwebview 指向网页的链接。5.2.0
max-content-lengthnumber最大下载长度限制,超过这个值时,不进行下载调用,单位 KB5.2.0
bindonpagestartedeventhandler网页开始加载时触发此事件。e.detail = { pageUrl:"xxx"}5.2.0
bindonprogresschangedeventhandler加载进度变化时触发此事件。e.detail = { type: "onProgressChanged", newProgress:xxx}
bindonpagefinishedeventhandler加载完成时触发此事件。e.detail = { type: "onPageFinished", pageUrl:xxx}
bindonreceivederroreventhandler网页加载失败时触发此事件。 e.detail = { type: "onReceivedError" isForMainFrame: true/false, pageUrl: "xxx", errorCode: "xxx", isRedirect: true/false, description: "xxx" }5.2.0
bindonreceivedhttperroreventhandler网页加载失败时触发此事件。 e.detail = { type: "onReceivedHttpError", isForMainFrame: true/false, pageUrl: "xxx", errorCode: "xxx", isRedirect: true/false, errorReasonPhrase: "xxx" }5.2.0
bindonreceivedtitleeventhandler网页加载过程中获取到 title 时触发此事件。e.detail = {title: xxx}5.2.0
bindonreceivediconeventhandler网页加载过程中获取到 icon 时触发此事件。e.detail = {favicon:xxx}5.2.0
bindsyncpagestackeventhandlerwebview内前进或者后退时触发此事件。e.detail = { canGoBack,canGoForward}
bindonreceivedschemeurleventhandlerWebivew 拦截到 scheme 跳转事件时触发.e.detail = { schemeUrl }5.2.0

使用示例

<native-webview 
id="myWebview"
:src="src"
:max-content-length="maxContentLength"
bind:bindonpagestarted="bindonpagestarted"
bind:bindonprogresschanged="bindonprogresschanged"
bind:bindonpagefinished="bindonpagefinished"
bind:bindonreceivederror="bindonreceivederror"
bind:bindonreceivedhttperror="bindonreceivedhttperror"
bind:bindonreceivedtitle="bindonreceivedtitle"
bind:bindonreceivedicon="bindonreceivedicon"
bind:bindsyncpagestack="bindsyncpagestack"
bind:bindonreceivedschemeurl="bindonreceivedschemeurl"
>
</native-webview>
Page({
data: {
src: "https://open.dlight-app.com/miniapp/docs/api/VideoContext/",
maxContentLength: 102400
},
onReady() {
this.webviewContext = dlt.createWebviewContext("myWebview");
},
bindonpagestarted(e) {
console.log("bindonpagestarted", e);
},
bindonprogresschanged(e) {
console.log("bindonprogresschanged", e);
},
bindonpagefinished(e) {
console.log("bindonpagefinished", e);
},
bindonreceivederror(e) {
console.log("bindonreceivederror", e);
},
bindonreceivedhttperror(e) {
console.log("bindonreceivedhttperror", e);
},
bindonreceivedtitle(e) {
// 网页标题
console.log("bindonreceivedtitle", e.detail.title);
},
bindonreceivedicon(e) {
// 网页 icon
console.log("bindonreceivedtitle", e.detail.favicon);
},
handleReload() {
this.webviewContext && this.webviewContext.reload();
},
handlegoBack() {
this.webviewContext && this.webviewContext.goBack();
},
handlegoForward() {
this.webviewContext && this.webviewContext.goForward();
},
loadUrl() {
this.webviewContext &&
this.webviewContext
.loadUrl("https://open.dlight-app.com/miniapp/docs/components/media/video")
.then((res) => console.log(res));
},
bindsyncpagestack(){
console.log("===bindsyncpagestack==", e)
},
bindonreceivedschemeurl(e){
console.log('===bindonreceiveschemeurl===', e.detail.schemeUrl);
}
});
Privacy agreementDeveloper agreementcontact us: developer_service.mi@transsion.com © 2024 MiniApp. All Rights Reserved.