提交 8326e10f 编写于 作者: DCloud-yinjiacheng's avatar DCloud-yinjiacheng

更新web-view示例

上级 230cf605
<template> <template>
<web-view ref="web-view" class="web-view" src="/hybrid/html/local.html" @message="message" @error="error" <web-view ref="web-view" class="web-view" src="/hybrid/html/local.html" @message="message" @error="error"
@loading="loading" @loaded="loaded"> @loading="loading" @load="load">
</web-view> </web-view>
</template> </template>
...@@ -13,23 +13,23 @@ ...@@ -13,23 +13,23 @@
} }
}, },
methods: { methods: {
message(event : WebViewMessageEvent) { message(event : UniWebViewMessageEvent) {
console.log(JSON.stringify(event.detail)); console.log(JSON.stringify(event));
uni.showModal({ uni.showModal({
content: JSON.stringify(event.detail), content: JSON.stringify(event.detail),
showCancel: false showCancel: false
}); });
}, },
error(event : WebViewErrorEvent) { error(event : UniWebViewErrorEvent) {
this.loadError = true this.loadError = true
console.log(JSON.stringify(event.detail)); console.log(JSON.stringify(event));
}, },
loading(event : WebViewLoadingEvent) { loading(event : UniWebViewLoadingEvent) {
console.log(JSON.stringify(event.type)); console.log(JSON.stringify(event));
}, },
loaded(event : WebViewLoadedEvent) { load(event : UniWebViewLoadEvent) {
this.loadFinish = true; this.loadFinish = true;
console.log(JSON.stringify(event.type)); console.log(JSON.stringify(event));
} }
} }
} }
......
<template> <template>
<view class="uni-flex-item"> <view class="uni-flex-item">
<web-view id="web-view" class="uni-flex-item" :src="src" :webview-styles="webview_styles" @message="message" <web-view id="web-view" class="uni-flex-item" :src="src" :webview-styles="webview_styles" @message="message"
@error="error" @loading="loading" @loaded="loaded" @download="download"> @error="error" @loading="loading" @load="load" @download="download">
</web-view> </web-view>
<view class="uni-padding-wrap uni-common-mt"> <view class="uni-padding-wrap uni-common-mt">
<view class="uni-input-v"> <view class="uni-input-v">
...@@ -58,27 +58,27 @@ ...@@ -58,27 +58,27 @@
nativeToWeb() { nativeToWeb() {
this.webviewContext?.evalJS("alert('hello uni-app x')"); this.webviewContext?.evalJS("alert('hello uni-app x')");
}, },
message(event : WebViewMessageEvent) { message(event : UniWebViewMessageEvent) {
console.log(JSON.stringify(event)); console.log(JSON.stringify(event));
}, },
error(event : WebViewErrorEvent) { error(event : UniWebViewErrorEvent) {
this.loadError = true this.loadError = true
console.log(JSON.stringify(event)); console.log(JSON.stringify(event));
}, },
loading(event : WebViewLoadingEvent) { loading(event : UniWebViewLoadingEvent) {
console.log(JSON.stringify(event)); console.log(JSON.stringify(event));
}, },
loaded(event : WebViewLoadedEvent) { load(event : UniWebViewLoadEvent) {
console.log(JSON.stringify(event)); console.log(JSON.stringify(event));
}, },
download(event : WebViewDownloadEvent) { download(event : UniWebViewDownloadEvent) {
console.log(JSON.stringify(event)); console.log(JSON.stringify(event));
uni.showModal({ uni.showModal({
content: "下载链接: " + event.detail.url + "\n文件大小: " + event.detail.contentLength / 1024 + "KB", content: "下载链接: " + event.detail.url + "\n文件大小: " + event.detail.contentLength / 1024 + "KB",
showCancel: false showCancel: false
}); });
}, },
confirm(event : InputConfirmEvent) { confirm(event : UniInputConfirmEvent) {
console.log(JSON.stringify(event)); console.log(JSON.stringify(event));
let url = event.detail.value; let url = event.detail.value;
if (!url.startsWith('https://') && !url.startsWith('http://')) { if (!url.startsWith('https://') && !url.startsWith('http://')) {
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册