unibest/src/pages/my/index.vue
2024-01-20 18:41:18 +08:00

36 lines
771 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.

<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>