个人中心账号复制,切换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>
<view class="user-info flex px-[50rpx] justify-between py-[50rpx]">
<navigator
<view
v-if="isLogin"
class="flex items-center"
hover-class="none"
url="/pages/user_data/user_data"
@click="navigateTo('/pages/user_data/user_data')"
>
<u-avatar :src="user.avatar" :size="120"></u-avatar>
<view class="text-white ml-[20rpx]">
<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>
</navigator>
</view>
<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>
<view class="text-white text-3xl ml-[20rpx]">未登录</view>
@ -22,6 +23,8 @@
</view>
</template>
<script lang="ts" setup>
import { useCopy } from '@/hooks/useCopy'
const props = defineProps({
content: {
type: Object,
@ -39,6 +42,12 @@ const props = defineProps({
type: Boolean
}
})
const { copy } = useCopy()
const navigateTo = (url: string) => {
uni.navigateTo({
url
})
}
</script>
<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
// v-model
this.$emit("change", index);
uni.switchTab({
url: pagePath
});
// uni.switchTab({
// url: pagePath
// });
} else {
// papgePathv-modelvalue
// v-modelvaluegetCurrentPages()