uniapp webview传值

<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>本地网页</title>
</head>
<body>
<p class="desc">web-view</p>
<!-- uni 的 SDK -->
<script type="text/javascript" src="https://js.cdn.aliyun.dcloud.net.cn/dev/uni-app/uni.webview.1.5.1.js"></script>
<script src="https://apps.bdimg.com/libs/jquery/2.1.4/jquery.min.js"> </script>
<script type="text/javascript">
console.log(window.location.search)
document.addEventListener('UniAppJSBridgeReady', function() {
$('.desc').click(function(){
uni.postMessage({
data: {
action: 'alert',
title:"你好"
}
});
})
});
</script>
</body>
</html>


******************************************↑↑↑↑↑↑  http://192.168.0.105:8080/a.html   ↑↑↑↑↑****************************************

 


*****************************************↓↓↓↓↓↓↓  webview.vue  ↓↓↓↓↓↓↓****************************************

 

<template>
<view>
<web-view :src="src" @message="message"> </web-view>
</view>
</template>
<script>
export default {
data(){
return {
src:""
}
},
onLoad() {
this.src='http://192.168.0.105:8080/a.html'
},
methods: {
message(event){
let data = (event.detail.data)[0];
console.log(data.action)
if(data.action == 'alert'){
uni.showModal({
title:data.title
});
this.src='http://192.168.0.105:8080/a.html?a=1'
}
}
}
}
</script>

 

posted @ 2020-05-22 00:00  mrt_yy  阅读(802)  评论(0编辑  收藏  举报