web-view-local.uvue 1.4 KB
Newer Older
DCloud-yinjiacheng's avatar
DCloud-yinjiacheng 已提交
1 2
<template>
	<view class="uni-flex-item">
DCloud-yinjiacheng's avatar
DCloud-yinjiacheng 已提交
3 4
		<web-view ref="web-view" class="uni-flex-item" src="/hybrid/html/local.html" @message="message" @error="error"
			@loading="loading" @loaded="loaded">
DCloud-yinjiacheng's avatar
DCloud-yinjiacheng 已提交
5 6 7 8 9 10 11 12 13 14 15 16
		</web-view>
	</view>
</template>

<script>
	export default {
		data() {
			return {

			}
		},
		methods: {
DCloud-yinjiacheng's avatar
DCloud-yinjiacheng 已提交
17
			message(event : WebViewMessageEvent) {
DCloud-yinjiacheng's avatar
DCloud-yinjiacheng 已提交
18
				console.log(JSON.stringify(event.detail));
DCloud-yinjiacheng's avatar
DCloud-yinjiacheng 已提交
19 20
				const data = event.detail.data;
				if (data == null) return;
DCloud-yinjiacheng's avatar
DCloud-yinjiacheng 已提交
21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54
				switch (data['action']) {
					case 'navigateTo':
						uni.navigateTo({
							url: data['url'] as string
						});
						break;
					case 'redirectTo':
						uni.redirectTo({
							url: data['url'] as string
						});
						break;
					case 'switchTab':
						uni.switchTab({
							url: data['url'] as string
						});
						break;
					case 'reLaunch':
						uni.reLaunch({
							url: data['url'] as string
						});
						break;
					case 'navigateBack':
						uni.navigateBack({
							delta: data['delta'] as number
						});
						break;
					default:
						uni.showModal({
							content: JSON.stringify(event.detail),
							showCancel: false
						});
						break;
				}
			},
DCloud-yinjiacheng's avatar
DCloud-yinjiacheng 已提交
55
			error(event : WebViewErrorEvent) {
DCloud-yinjiacheng's avatar
DCloud-yinjiacheng 已提交
56 57
				console.log(JSON.stringify(event.detail));
			},
DCloud-yinjiacheng's avatar
DCloud-yinjiacheng 已提交
58
			loading(event : WebViewLoadingEvent) {
DCloud-yinjiacheng's avatar
DCloud-yinjiacheng 已提交
59 60
				console.log(JSON.stringify(event.type));
			},
DCloud-yinjiacheng's avatar
DCloud-yinjiacheng 已提交
61
			loaded(event : WebViewLoadedEvent) {
DCloud-yinjiacheng's avatar
DCloud-yinjiacheng 已提交
62 63 64 65 66 67 68 69 70
				console.log(JSON.stringify(event.type));
			}
		}
	}
</script>

<style>

</style>