feat: 根据需要处理H5传递过来的消息
This commit is contained in:
@@ -1,6 +1,6 @@
|
|||||||
<template>
|
<template>
|
||||||
<view>
|
<view>
|
||||||
<web-view :src="webviewUrl"></web-view>
|
<web-view :src="webviewUrl" @message="handleH5Message"></web-view>
|
||||||
</view>
|
</view>
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
@@ -21,6 +21,26 @@ onMounted(() => {
|
|||||||
webviewUrl.value = decodeURIComponent(options.url);
|
webviewUrl.value = decodeURIComponent(options.url);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
const handleH5Message = (event) => {
|
||||||
|
const messageData = event.detail.data;
|
||||||
|
console.log("Received message from H5:", messageData);
|
||||||
|
// 根据需要处理H5传递过来的消息
|
||||||
|
const action = messageData[0].action
|
||||||
|
|
||||||
|
switch (action) {
|
||||||
|
case "navigateBack":
|
||||||
|
uni.navigateBack();
|
||||||
|
break;
|
||||||
|
case "navigateTo":
|
||||||
|
|
||||||
|
break
|
||||||
|
default:
|
||||||
|
console.log("Unknown action:", action);
|
||||||
|
}
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<style lang="scss" scoped></style>
|
<style lang="scss" scoped></style>
|
||||||
|
|||||||
Reference in New Issue
Block a user