Files
YGChatCS/src/pages/webview/index.vue

47 lines
999 B
Vue
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<template>
<view>
<web-view :src="webviewUrl" @message="handleH5Message"></web-view>
</view>
</template>
<script setup>
import { ref, onMounted } from "vue";
const webviewUrl = ref("");
onMounted(() => {
// 获取页面参数
const pages = getCurrentPages();
const currentPage = pages[pages.length - 1];
const options = currentPage.options;
// 从页面参数中获取url
if (options.url) {
// 对URL进行解码因为传递时可能被编码了
webviewUrl.value = decodeURIComponent(options.url);
}
});
const handleH5Message = (event) => {
const messageData = event.detail.data[0];
console.log("Received message from H5:", messageData);
// 根据需要处理H5传递过来的消息
const action = messageData.action;
switch (action) {
case "navigateBack":
uni.navigateBack();
break;
case "navigateTo":
break
default:
console.log("Unknown action:", action);
}
};
</script>
<style lang="scss" scoped></style>