uniapp 使用webview

返回的数据:

{
	"type": "message",
	"target": {},
	"currentTarget": {},
	"timeStamp": 1593413171731,
	"detail": {
		"data": [{
			"action": "message",
			"id": "2020",
			"type": "copy"
		}]
	}
}


{
	"action": "message",
	"id": "2020",
	"type": "copy"
}


<template>
    <view>
		<web-view title="hehe" :webview-styles="webviewStyles" 
		:src="url" 
		@message="message"
		@onPostMessage = "onPostMessage">
		</web-view>
		
		
		
    </view>
</template>


<script>
	
	var wv;//计划创建的webview
    export default {
		
        data() {
            return {
                webviewStyles: {
                    progress: {
                        color: '#3e3adc'
                    }
                },
				url:'',
            }
        },
		onLoad() {
			console.log('x')
			// http://api.chexiang365.net/activety/test.html?ext_code=11111
			// this.url='http://api.chexiang365.net/activety/test.html?ext_code=2020ax'
			var u_id = this.$userFind.u_id
			console.log(u_id)
			// return
			// var data = btoa(btoa(u_id))
			
			var data_old = this.$myApi.base64_encode_api(u_id)
			var data = this.$myApi.base64_encode_api(data_old)
			// console.log(data_new)
			const url = 'http://myphpmy.vip/web/demo.html'
			
			// const url = 'file:///C:/Users/deng/Desktop/wwwa/demo.html'
			// const url = 'http://192.168.5.56:8080/#/h5/invit/'+data
			// const url = 'https://api.chexiang365.net/#/h5/invitInput/'+data
			
			
			console.log(url)
			this.url = url
			
		},
		onShow(){
		},
		methods:{
			onPostMessage(){
				console.log('xxxonPostMessage')
			},
			demo(){
				console.log('xxxxxxxxxx')
			},
			message(event){
				console.log('触发事件')
				const data = event.detail.data[0]
				console.log(data)
				console.log('___________')
				const action = data.action
				console.log(action)
				console.log('messagemessagemessagemessagemessage')
				uni.showModal({
				    title: '提示',
				    content: data.type,
				    success: function (res) {
				        if (res.confirm) {
				            console.log('用户点击确定');
				        } else if (res.cancel) {
				            console.log('用户点击取消');
				        }
				    }
				});
				console.log(event)
				console.log('xxx')
			}
		}
    }
	
</script>

<style>

</style>
H5<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8" />
		<meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1,maximum-scale=1,user-scalable=no" />
		<title>网络网页</title>
		<style type="text/css">
			.btn {
				display: block;
				margin: 20px auto;
				padding: 5px;
				background-color: #007aff;
				border: 0;
				color: #ffffff;
				height: 40px;
				width: 200px;
			}

			.btn-red {
				background-color: #dd524d;
			}

			.btn-yellow {
				background-color: #f0ad4e;
			}

			.desc {
				padding: 10px;
				color: #999999;
			}

			.post-message-section {
				visibility: hidden;
			}
		</style>
	</head>
	<body>
		<p class="desc">web-view 组件加载网络 html 示例。点击下列按钮,跳转至其它页面。</p>
		<div class="btn-list">
			<button class="btn" type="button" data-action="switchTab">switchTab</button>
		</div>
		<div class="post-message-section">
			<p class="desc">网页向应用发送消息,注意:小程序端应用会在此页面后退时接收到消息。</p>
			<div class="btn-list">
				<button class="btn btn-red" type="button" id="postMessage">postMessage</button>
			</div>
		</div>
		<script type="text/javascript">
			var userAgent = navigator.userAgent;
			if (userAgent.indexOf('AlipayClient') > -1) {
				// 支付宝小程序的 JS-SDK 防止 404 需要动态加载,如果不需要兼容支付宝小程序,则无需引用此 JS 文件。
				document.writeln('
                    
                    

你可能感兴趣的:(Uniapp)