36 lines
771 B
Vue
36 lines
771 B
Vue
<route lang="json5">
|
||
{
|
||
style: { navigationBarTitleText: '我的' },
|
||
}
|
||
</route>
|
||
<template>
|
||
<view>我的</view>
|
||
<view>wx的openid:{{ openId }} </view>
|
||
<wx-login />
|
||
</template>
|
||
|
||
<script lang="ts" setup>
|
||
import { useUserStore } from '@/store'
|
||
import { http } from '@/utils/http'
|
||
import WxLogin from './components/wx-login.vue'
|
||
|
||
const userStore = useUserStore()
|
||
const openId = ref('')
|
||
|
||
// 用户登录,获取openId
|
||
uni.login({
|
||
provider: 'weixin',
|
||
success: async ({ code }) => {
|
||
const res = await http<{ session_key: string; openid: string }>({
|
||
method: 'GET',
|
||
url: '/weixin/jscode2session',
|
||
data: {
|
||
code,
|
||
},
|
||
})
|
||
openId.value = res.result.openid
|
||
userStore.setUserInfo({ openid: res.result.openid })
|
||
},
|
||
})
|
||
</script>
|