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

更新web-view示例

上级 35f3dbfb
<template>
<view class="uni-flex-item">
<web-view ref="web-view" class="uni-flex-item" src="/hybrid/html/local.html" @onPostMessage="onPostMessage"
@error="error" @loading="loading" @loaded="loaded">
<web-view ref="web-view" class="uni-flex-item" src="/hybrid/html/local.html" @message="message" @error="error"
@loading="loading" @loaded="loaded">
</web-view>
<view class="uni-padding-wrap uni-common-mt">
<view class="uni-btn-v">
......@@ -21,7 +21,6 @@
</template>
<script>
import JSONObject from 'com.alibaba.fastjson.JSONObject';
export default {
data() {
return {
......@@ -41,9 +40,10 @@
stop() {
(this.$refs['web-view'] as IWebViewNode).stop();
},
onPostMessage(event: WebViewPostMessageEvent) {
message(event: WebViewMessageEvent) {
console.log(JSON.stringify(event.detail));
const data = event.detail.data as JSONObject;
const data = event.detail.data;
if (data == null) return;
switch (data['action']) {
case 'navigateTo':
uni.navigateTo({
......
<template>
<view class="uni-flex-item">
<web-view ref="web-view" class="uni-flex-item" :src="src" :webview-styles="webview_styles"
@onPostMessage="onPostMessage" @error="error" @loading="loading" @loaded="loaded">
<web-view ref="web-view" class="uni-flex-item" :src="src" :webview-styles="webview_styles" @message="message"
@error="error" @loading="loading" @loaded="loaded">
</web-view>
<view class="uni-padding-wrap uni-common-mt">
<view class="uni-btn-v">
......@@ -21,7 +21,6 @@
</template>
<script>
import JSONObject from 'com.alibaba.fastjson.JSONObject';
export default {
data() {
return {
......@@ -46,9 +45,10 @@
stop() {
(this.$refs['web-view'] as IWebViewNode).stop();
},
onPostMessage(event: WebViewPostMessageEvent) {
message(event: WebViewMessageEvent) {
console.log(JSON.stringify(event.detail));
const data = event.detail.data as JSONObject;
const data = event.detail.data;
if (data == null) return;
switch (data['action']) {
case 'navigateTo':
uni.navigateTo({
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册