小程序登陆后把token和openId 对应传到pc端 pc端有两套一套pc端代码和适应移动端的代码 嵌套的是适应移动端的代码
1.uniapp
javascript
<template>
<view class="main">
<u-navbar :fixed="true" :autoBack="false" @leftClick="goBack"></u-navbar>
<web-view :src="url" @message="message"></web-view>
</view>
</template>
<script>
export default {
data() {
return {
url: '',
token: '',
canBack: false,
openId: ''
}
},
onLoad() {
this.token = uni.getStorageSync('token');
this.openId = uni.getStorageSync('openid');
this.url = 'http://192.168.31.190:8888/mobile/?token=' + encodeURIComponent(this.token) + '&openId=' +
encodeURIComponent(this.openId)
console.log(this.url)
},
methods: {
message(event) {
console.log(event.detail.data);
},
},
}
</script>
<style>
.main {
width: 100%;
height: 100vh;
}
</style>
2.vue3+vant pc端接收参数
javascript
const token = ref("")
const openId = ref("")
onMounted(() => {
var url = window.location.href;
console.log(url)
var regex = /[?&]token=([^&#]+)/; // 匹配 ? 或 & 后面跟 token= 开头的部分
var regexId = /[?&]openId=([^&#]+)/; // 匹配 ? 或 & 后面跟 token= 开头的部分
var match = url.match(regex);
token.value = decodeURIComponent(match[1]);
openId.value = decodeURIComponent(url.match(regexId)[1]);
})