一个简单的商城

1,首先在src目录下创建一个名为pages的文件夹,然后

在该文件中创建一个名为index.vue的文件。

这是商城的首页

打开index.vue文件,编写如下代码:

<template>  
 <view class="container">  
   <view class="header">  
     <image class="logo" src="/static/logo.png" />  
     <text class="title">欢迎来到 uni-APP 商城</text>  
   </view>  
   <view class="categories">  
     <nav-bar  
       title="商品分类"  
       @scrolltolower="loadMore"  
       :loadMore="loadMore"  
     ></nav-bar>  
     <scroll-view class="category-list" scroll-y="true">  
       <block v-for="(category, index) in categories" :key="index">  
         <view class="category-item" @tap="navToCategory(category.id)">  
           <text class="category-name">{{ category.name }}</text>  
         </view>  
       </block>  
     </scroll-view>  
   </view>  
   <view class="products">  
     <nav-bar  
       title="商品展示"  
       @scrolltolower="loadMore"  
       :loadMore="loadMore"  
     ></nav-bar>  
     <scroll-view class="product-list" scroll-y="true">  
       <block v-for="(product, index) in products" :key="index">  
         <view class="product-item" @tap="navToProduct(product.id)">  
           <image :src="product.image" class="product-image" />  
           <text class="product-name">{{ product.name }}</text>  
           <text class="product-price">¥{{ product.price }}</text>  
         </view>  
       </block>  
     </scroll-view>  
   </view>  
 </view>  
</template>

<script>  
import NavBar from "@/components/NavBar";

export default {  
 components: {  
   NavBar,  
 },  
 data() {  
   return {  
     categories: [  
       { id: 1, name: "服装" },  
       { id: 2, name: "鞋子" },  
       { id: 3, name: "配饰" },  
     ],  
     products: [  
       {  
         id: 1,  
         name: "商品 1",  
         image: "/static/product1.jpg",  
         price: 100,  
       },  
       {  
         id: 2,  
         name: "商品 2",  
         image: "/static/product2.jpg",  
         price: 200,  
       },  
       {  
         id: 3,  
         name: "商品 3",  
         image: "/static/product3.jpg",  
         price: 300,  
       },  
     ],  
   };  
 },  
 onLoad() {  
   this.loadMore();  
 },  
 methods: {  
   loadMore() {  
     setTimeout(() => {  
       this.products.push({  
         id: this.products.length + 1,  
         name: "新商品",  
         image: `/static/product${this.products.length}.jpg`,  
         price: 50,  
       });  
     }, 1000);  
   },  
   navToCategory(id) {  
     console.log("导航到分类", id);  
     // 跳转到分类页面  
   },  
   navToProduct(id) {  
     console.log("导航到产品", id);  
     // 跳转到产品详情页面  
   },  
 },  
};  
</script>

<style>  
.container {  
 display: flex;  
 flex-direction: column;  
 height: 100%;  
}
.header {  
 display: flex;  
 justify-content: space-between;  
 align-items: center;  
 padding: 10px;  
 background-color: #f8f8f8;  
 color: #333;

以上是商城的一个简单制作首页。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值