1. 首先,在uniapp项目的pages目录下新建一个名为“my”的文件夹,用于存放“我的”页面相关的文件。

  2. 在my文件夹下新建一个名为“my.vue”的文件,作为“我的”页面的主页面。

  3. 在my.vue文件中,编写HTML代码,包括页面布局、样式等内容。例如:

<template>
  <view class="container">
    <view class="header">
      <image class="avatar" src="../../static/avatar.png"></image>
      <view class="info">
        <text class="name">用户名</text>
        <text class="desc">个人简介</text>
      </view>
    </view>
    <view class="menu">
      <view class="item" @click="goToOrder">
        <image class="icon" src="../../static/order.png"></image>
        <text class="text">我的订单</text>
      </view>
      <view class="item" @click="goToCoupon">
        <image class="icon" src="../../static/coupon.png"></image>
        <text class="text">我的优惠券</text>
      </view>
      <view class="item" @click="goToAddress">
        <image class="icon" src="../../static/address.png"></image>
        <text class="text">收货地址</text>
      </view>
    </view>
  </view>
</template>

<style>
  .container {
    padding: 20rpx;
  }
  .header {
    display: flex;
    align-items: center;
    margin-bottom: 20rpx;
  }
  .avatar {
    width: 80rpx;
    height: 80rpx;
    border-radius: 50%;
  }
  .info {
    margin-left: 20rpx;
  }
  .name {
    font-size: 32rpx;
    font-weight: bold;
  }
  .desc {
    font-size: 28rpx;
    color: #999;
  }
  .menu {
    display: flex;
    flex-wrap: wrap;
  }
  .item {
    width: 33.33%;
    display: flex;
    flex-direction: column;
    align-items: center;
    margin-bottom: 20rpx;
  }
  .icon {
    width: 60rpx;
    height: 60rpx;
    margin-bottom: 10rpx;
  }
  .text {
    font-size: 28rpx;
  }
</style>
  1. 在my.vue文件中,编写JavaScript代码,包括页面逻辑、跳转等内容。例如:
<script>
  export default {
    methods: {
      goToOrder() {
        uni.navigateTo({
          url: '/pages/order/order'
        })
      },
      goToCoupon() {
        uni.navigateTo({
          url: '/pages/coupon/coupon'
        })
      },
      goToAddress() {
        uni.navigateTo({
          url: '/pages/address/address'
        })
      }
    }
  }
</script>
  1. 在uniapp项目的pages.json文件中,添加“我的”页面的配置信息。例如:
{
  "pages": [
    {
      "path": "pages/index/index",
      "style": {
        "navigationBarTitleText": "首页"
      }
    },
    {
      "path": "pages/category/category",
      "style": {
        "navigationBarTitleText": "分类"
      }
    },
    {
      "path": "pages/cart/cart",
      "style": {
        "navigationBarTitleText": "购物车"
      }
    },
    {
      "path": "pages/my/my",
      "style": {
        "navigationBarTitleText": "我的"
      }
    }
  ],
  "window": {
    "navigationBarBackgroundColor": "#fff",
    "navigationBarTextStyle": "black"
  }
}
  1. 在uniapp项目中运行“我的”页面,可以通过点击底部菜单栏上的“我的”按钮进入。如果底部菜单栏还未配置,请参考uniapp官方文档进行配置
uniapp生成一个我的页面

原文地址: https://www.cveoy.top/t/topic/hetc 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录