提交 79f85e81 编写于 作者: DCloud-yinjiacheng's avatar DCloud-yinjiacheng

更新web-view示例

上级 09275385
<template>
<view class="uni-flex-item">
<web-view id="web-view" class="uni-flex-item" :src="src" :webview-styles="webview_styles" @message="message"
@error="error" @loading="loading" @loaded="loaded">
@error="error" @loading="loading" @loaded="loaded" @download="download">
</web-view>
<view class="uni-padding-wrap uni-common-mt">
<view class="uni-input-v">
<input class="uni-input" confirmType="go" placeholder="输入网址跳转" @confirm="confirm" />
</view>
<view class="uni-row uni-btn-v">
<view class="uni-flex-item">
<button type="primary" @click="back">后退</button>
</view>
<view class="uni-btn-ml uni-flex-item">
<button type="primary" @click="forward">前进</button>
</view>
<button class="uni-flex-item" type="primary" @click="back">后退</button>
<button class="uni-btn-ml uni-flex-item" type="primary" @click="forward">前进</button>
</view>
<view class="uni-row uni-btn-v">
<view class="uni-flex-item">
<button type="primary" @click="reload">重新加载</button>
</view>
<view class="uni-btn-ml uni-flex-item">
<button type="primary" @click="stop">停止加载</button>
</view>
<button class="uni-flex-item" type="primary" @click="reload">重新加载</button>
<button class="uni-btn-ml uni-flex-item" type="primary" @click="stop">停止加载</button>
</view>
<view class="uni-btn-v">
<button type="primary" @click="nativeToWeb">原生和Web通信</button>
......@@ -64,20 +56,27 @@
this.webviewContext?.evalJS("alert('hello uni-app x')");
},
message(event : WebViewMessageEvent) {
console.log(JSON.stringify(event.detail));
console.log(JSON.stringify(event));
},
error(event : WebViewErrorEvent) {
this.loadError = true
console.log(JSON.stringify(event.detail));
console.log(JSON.stringify(event));
},
loading(event : WebViewLoadingEvent) {
console.log(JSON.stringify(event.type));
console.log(JSON.stringify(event));
},
loaded(event : WebViewLoadedEvent) {
console.log(JSON.stringify(event.type));
console.log(JSON.stringify(event));
},
download(event : WebViewDownloadEvent) {
console.log(JSON.stringify(event));
uni.showModal({
content: "下载链接: " + event.detail.url + "\n文件大小: " + event.detail.contentLength / 1024 + "KB",
showCancel: false
});
},
confirm(event : InputConfirmEvent) {
console.log(event.detail.value);
console.log(JSON.stringify(event));
let url = event.detail.value;
if (!url.startsWith('https://') && !url.startsWith('http://')) {
url = 'https://' + url;
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册