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

更新web-view示例

上级 a1f34f14
<template> <template>
<view class="uni-flex-item"> <view class="uni-flex-item">
<web-view ref="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"> @error="error" @loading="loading" @loaded="loaded">
</web-view> </web-view>
<view class="uni-padding-wrap uni-common-mt"> <view class="uni-padding-wrap uni-common-mt">
...@@ -39,24 +39,28 @@ ...@@ -39,24 +39,28 @@
progress: { progress: {
color: '#FF3333' color: '#FF3333'
} }
},
webviewContext: null as WebviewContext | null
} }
} },
onReady() {
this.webviewContext = uni.createWebviewContext('web-view', this)
}, },
methods: { methods: {
back() { back() {
(this.$refs['web-view'] as IWebViewNode).back(); this.webviewContext?.back();
}, },
forward() { forward() {
(this.$refs['web-view'] as IWebViewNode).forward(); this.webviewContext?.forward();
}, },
reload() { reload() {
(this.$refs['web-view'] as IWebViewNode).reload(); this.webviewContext?.reload();
}, },
stop() { stop() {
(this.$refs['web-view'] as IWebViewNode).stop(); this.webviewContext?.stop();
}, },
nativeToWeb() { nativeToWeb() {
(this.$refs['web-view'] as IWebViewNode).evalJS("alert('hello uni-app x')"); this.webviewContext?.evalJS("alert('hello uni-app x')");
}, },
message(event : WebViewMessageEvent) { message(event : WebViewMessageEvent) {
console.log(JSON.stringify(event.detail)); console.log(JSON.stringify(event.detail));
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册