当前位置:首页 > uni-app

uniapp我的页面

2026-02-06 09:28:48uni-app

uniapp 我的页面开发指南

页面结构设计

在uniapp中创建我的页面通常需要设计清晰的用户信息展示区、功能入口区和设置区。典型结构包括顶部用户信息卡片、中间功能列表和底部操作按钮。

<template>
  <view class="my-page">
    <!-- 用户信息区 -->
    <view class="user-card">
      <image class="avatar" :src="userInfo.avatar"></image>
      <text class="username">{{userInfo.name}}</text>
    </view>

    <!-- 功能列表区 -->
    <view class="func-list">
      <uni-list>
        <uni-list-item title="我的订单" showArrow></uni-list-item>
        <uni-list-item title="收货地址" showArrow></uni-list-item>
        <uni-list-item title="优惠券" showArrow></uni-list-item>
      </uni-list>
    </view>

    <!-- 设置按钮 -->
    <button class="logout-btn" @click="logout">退出登录</button>
  </view>
</template>

数据绑定与状态管理

需要处理用户登录状态和获取用户信息,建议使用vuex进行状态管理。

<script>
import { mapState } from 'vuex'

export default {
  computed: {
    ...mapState(['userInfo'])
  },
  methods: {
    logout() {
      uni.showModal({
        title: '提示',
        content: '确定要退出登录吗?',
        success: (res) => {
          if (res.confirm) {
            this.$store.commit('logout')
            uni.reLaunch({ url: '/pages/login/login' })
          }
        }
      })
    }
  }
}
</script>

样式优化

我的页面通常需要注重视觉体验,建议使用flex布局和适当的间距。

uniapp我的页面

<style lang="scss">
.my-page {
  padding: 20rpx;

  .user-card {
    display: flex;
    align-items: center;
    padding: 30rpx;
    background: linear-gradient(to right, #3a7bd5, #00d2ff);
    border-radius: 16rpx;
    margin-bottom: 30rpx;

    .avatar {
      width: 120rpx;
      height: 120rpx;
      border-radius: 50%;
      margin-right: 30rpx;
    }

    .username {
      color: white;
      font-size: 36rpx;
    }
  }

  .logout-btn {
    margin-top: 60rpx;
    background: #ff5a5f;
    color: white;
  }
}
</style>

登录状态处理

需要处理未登录状态的页面展示,可添加条件渲染。

<template>
  <view v-if="!isLogin" class="login-tip">
    <text>您还未登录</text>
    <button @click="goLogin">去登录</button>
  </view>
  <view v-else>
    <!-- 已登录内容 -->
  </view>
</template>

性能优化

对于我的页面中的图片资源,建议使用懒加载和合适的CDN加速。

uniapp我的页面

<image lazy-load :src="userInfo.avatar" mode="aspectFill"></image>

平台适配

不同平台可能需要特殊处理,如小程序和H5的差异。

onLoad() {
  // #ifdef H5
  this.initWebUser()
  // #endif
  // #ifdef MP-WEIXIN
  this.getWeixinUser()
  // #endif
}

安全考虑

用户敏感信息需要做好保护,避免直接显示完整手机号等。

computed: {
  safePhone() {
    return this.userInfo.phone.replace(/(\d{3})\d{4}(\d{4})/, '$1$2')
  }
}

标签: 我的页面
分享给朋友:

相关文章

js实现页面跳转

js实现页面跳转

使用 window.location.href 通过修改 window.location.href 实现页面跳转,直接赋值目标 URL 即可。 window.location.href = 'h…

vue实现单页面

vue实现单页面

Vue 实现单页面应用(SPA)的方法 Vue.js 是一个渐进式框架,适合构建单页面应用(SPA)。以下是实现 SPA 的核心步骤和关键配置。 安装 Vue 和 Vue Router 确保已安装…

Vue实现lagger页面

Vue实现lagger页面

Vue实现懒加载页面的方法 懒加载(Lazy Loading)是一种优化技术,用于延迟加载非关键资源,从而提升页面初始加载速度。在Vue中可以通过以下方式实现懒加载: 路由懒加载 使用Vue Rou…

js实现页面加载

js实现页面加载

监听 DOMContentLoaded 事件 使用 DOMContentLoaded 事件可以在 HTML 文档完全加载和解析后触发,无需等待样式表、图像等外部资源加载完成。 document.…

js实现刷新页面

js实现刷新页面

刷新页面的方法 在JavaScript中,可以通过多种方式实现页面刷新。以下是几种常见的方法: 使用 location.reload() 调用 location.reload() 方法可以重新加载当…

vue单页面实现

vue单页面实现

Vue 单页面应用(SPA)实现指南 Vue.js 是一个流行的前端框架,适合构建单页面应用(SPA)。以下是实现 Vue SPA 的关键步骤和技术要点。 项目初始化 使用 Vue CLI 快速搭建…