unibest/src/pages/my/index.vue

36 lines
771 B
Vue
Raw Normal View History

<route lang="json5">
{
style: { navigationBarTitleText: '我的' },
}
</route>
2024-01-03 17:09:44 +08:00
<template>
<view>我的</view>
2024-01-20 18:21:42 +08:00
<view>wx的openid:{{ openId }} </view>
2024-01-20 18:41:18 +08:00
<wx-login />
2024-01-03 17:09:44 +08:00
</template>
2024-01-16 10:15:20 +08:00
<script lang="ts" setup>
2024-01-20 18:21:42 +08:00
import { useUserStore } from '@/store'
import { http } from '@/utils/http'
2024-01-20 18:41:18 +08:00
import WxLogin from './components/wx-login.vue'
2024-01-20 18:21:42 +08:00
const userStore = useUserStore()
const openId = ref('')
2024-01-16 10:15:20 +08:00
// 用户登录获取openId
2024-01-20 18:21:42 +08:00
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
2024-01-20 18:41:18 +08:00
userStore.setUserInfo({ openid: res.result.openid })
2024-01-20 18:21:42 +08:00
},
})
2024-01-16 10:15:20 +08:00
</script>