gpt-3.5-turbo-0613· OpenAI
WildChat-4.8M (AI2)
微信小程序开发商城页面代码
- User
微信小程序开发商城页面代码
- Assistant
以下是一个简单的微信小程序商城页面的代码示例:
<!--index.wxml--> <view class="container"> <view class="topbar"> <image class="logo" src="/images/logo.png"></image> <text class="title">MyShop</text> <view class="cart-icon"> <image src="/images/cart.png"></image> <text class="cart-count">{{cartCount}}</text> </view> </view> <view class="product-list"> <block wx:for="{{products}}" wx:key="{{index}}"> <view class="product-item"> <image class="product-image" src="{{item.image}}"></image> <text class="product-name">{{item.name}}</text> <text class="product-price">¥ {{item.price}}</text> <button class="add-to-cart" data-index="{{index}}" bindtap="addToCart">加入购物车</button> </view> </block> </view> </view>/*index.wxss*/ .container { padding: 20px; } .topbar { display: flex; justify-content: space-between; align-items: center; margin-bottom: 20px; } .logo { width: 80px; height: 80px; } .title { font-size: 24px; font-weight: bold; } .cart-icon { display: flex; align-items: center; position: relative; } .cart-count { position: absolute; top: -8px; right: -8px; font-size: 12px; color: #fff; background-color: #f00; border-radius: 50%; width: 16px; height: 16px; display: flex; align-items: center; justify-content: center; visibility: {{cartCount > 0 ? 'visible' : 'hidden'}}; } .product-list { display: flex; flex-wrap: wrap; } .product-item { width: 50%; padding: 10px; box-sizing: border-box; } .product-image { width: 100%; height: 200px; } .product-name { font-size: 16px; margin-top: 10px; } .product-price { font-size: 14px; color: #f00; margin-top: 5px; } .add-to-cart { width: 100%; border: none; background-color: #f00; color: #fff; font-size: 16px; padding: 10px; margin-top: 10px; border-radius: 10px; }//index.js Page({ data: { products: [ { name: "商品1", price: 10, image: "/images/product1.png" }, { name: "商品2", price: 20, image: "/images/product2.png" }, { name: "商品3", price: 30, image: "/images/product3.png" } ], cartCount: 0 }, addToCart: function(e) { const index = e.currentTarget.dataset.index; const product = this.data.products[index]; // 将商品添加到购物车 console.log('添加到购物车:', product); // 更新购物车数量 this.setData({ cartCount: this.data.cartCount + 1 }); } });请注意,以上代码仅是一个简单的示例,用于展示一个基本的微信小程序商城页面的结构和交互逻辑。实际开发中,您可能需要根据自己的需求进行修改和优化。
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.