个人中心账号复制,切换tab页面时报错

This commit is contained in:
Jason 2022-09-20 11:36:41 +08:00
parent b512eac708
commit 77fb6acc2d
3 changed files with 27 additions and 8 deletions

View File

@ -1,17 +1,18 @@
<template> <template>
<view class="user-info flex px-[50rpx] justify-between py-[50rpx]"> <view class="user-info flex px-[50rpx] justify-between py-[50rpx]">
<navigator <view
v-if="isLogin" v-if="isLogin"
class="flex items-center" class="flex items-center"
hover-class="none" @click="navigateTo('/pages/user_data/user_data')"
url="/pages/user_data/user_data"
> >
<u-avatar :src="user.avatar" :size="120"></u-avatar> <u-avatar :src="user.avatar" :size="120"></u-avatar>
<view class="text-white ml-[20rpx]"> <view class="text-white ml-[20rpx]">
<view class="text-2xl">{{ user.nickname }}</view> <view class="text-2xl">{{ user.nickname }}</view>
<view class="text-xs mt-[18rpx]">账号{{ user.username }}</view> <view class="text-xs mt-[18rpx]" @click.stop="copy(user.username)">
账号{{ user.username }}
</view>
</view>
</view> </view>
</navigator>
<navigator v-else class="flex items-center" hover-class="none" url="/pages/login/login"> <navigator v-else class="flex items-center" hover-class="none" url="/pages/login/login">
<u-avatar src="/static/images/user/default_avatar.png" :size="120"></u-avatar> <u-avatar src="/static/images/user/default_avatar.png" :size="120"></u-avatar>
<view class="text-white text-3xl ml-[20rpx]">未登录</view> <view class="text-white text-3xl ml-[20rpx]">未登录</view>
@ -22,6 +23,8 @@
</view> </view>
</template> </template>
<script lang="ts" setup> <script lang="ts" setup>
import { useCopy } from '@/hooks/useCopy'
const props = defineProps({ const props = defineProps({
content: { content: {
type: Object, type: Object,
@ -39,6 +42,12 @@ const props = defineProps({
type: Boolean type: Boolean
} }
}) })
const { copy } = useCopy()
const navigateTo = (url: string) => {
uni.navigateTo({
url
})
}
</script> </script>
<style lang="scss" scoped> <style lang="scss" scoped>

10
app/src/hooks/useCopy.ts Normal file
View File

@ -0,0 +1,10 @@
export function useCopy() {
const copy = (text: string) => {
uni.setClipboardData({
data: String(text)
})
}
return {
copy
}
}

View File

@ -245,9 +245,9 @@ export default {
if(pagePath == this.pageUrl || pagePath == "/" + this.pageUrl) return if(pagePath == this.pageUrl || pagePath == "/" + this.pageUrl) return
// v-model // v-model
this.$emit("change", index); this.$emit("change", index);
uni.switchTab({ // uni.switchTab({
url: pagePath // url: pagePath
}); // });
} else { } else {
// papgePathv-modelvalue // papgePathv-modelvalue
// v-modelvaluegetCurrentPages() // v-modelvaluegetCurrentPages()