惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
The Cloudflare Blog
有赞技术团队
有赞技术团队
H
Help Net Security
V
Visual Studio Blog
F
Fortinet All Blogs
Apple Machine Learning Research
Apple Machine Learning Research
博客园 - 司徒正美
G
Google Developers Blog
Google DeepMind News
Google DeepMind News
腾讯CDC
H
Hackread – Cybersecurity News, Data Breaches, AI and More
Stack Overflow Blog
Stack Overflow Blog
I
InfoQ
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
L
LangChain Blog
N
Netflix TechBlog - Medium
罗磊的独立博客
The GitHub Blog
The GitHub Blog
云风的 BLOG
云风的 BLOG
Hugging Face - Blog
Hugging Face - Blog
A
About on SuperTechFans
aimingoo的专栏
aimingoo的专栏
Recent Announcements
Recent Announcements

秋码分享

我是如何解决将 c++ 编译成可以在 node.js 中使用的 *.node,中间出现的一大堆问题的(指纹浏览器基石篇) eSIM Plus 爱沙尼亚手机号彻底翻车?“永久有效”悄然变成了一年! 接码平台 SMS-Activate 余额可以转移到新平台使用,截止日期:2026年1月29日 是时候将 hugo-theme-kiwi 主题提交到 themes.gohugo.io 站点上了 Flux2 刚开源就凉了?Z-Image 本地部署狠狠打了个样 声音的未来:Chatterbox —— 用「夸张度旋钮」提升表现力的开源 TTS 向导 还以为那只是换个背景?Qwen-Image-Edit 在 ComfyUI 中能做到更离谱的事 Windows 结合最新版 ComfyUI 部署阿里最新开源的 Qwen-Image 图像大模型 从零样本到跨场景:Seed-VC语音转换技术的革命性突破 大语音模型轻量化革命:MegaTTS3 如何重新定义文本生成语音的技术边界(windows篇) 竞赛级编程大模型OlympicCoder-7B之本地部署(Windows篇) 阿里开源了端到端全模态大模型Qwen-2.5-Omini-7B之本地部署(windows篇) 语音识别之whisper本地部署(实时语音之开篇) 甭管是个人还是企业都能部署的Mistral-Small3.1,远超同级别的模型 文生音乐开源项目DiffRhythm,8G显存本地部署之Windows篇 阿里QwQ-32B本地部署指南:用Ollama轻松运行320亿参数大模型 基于Qwen2.5大模型的Spark-TTS,零样本语音克隆,CPU可运行之本地部署(Windows篇) 智谱开源了文生图CogView4-6B模型,支持中文提示词之本地部署(Windows篇) 基于歌词生成整首歌的开源AI音乐模型,支持中、英、日、韩等多种语言,本地化部署YuE(windows篇) 阿里云开源的文生视频万相 Wan2.1之本地部署Wan2.1-T2V-1.3B模型 互动式开源AI图像编辑神器,Windows11本地部署 MagicQuill 本地部署Qwen2.5-VL-7B-Instruct多模态视觉大模型(Windows篇) 保持角色一致性的绘本生成AI开源项目之Story-Adapter本地部署Windows篇 本地部署 Stable Diffusion 3.5(最新 ComfyUI记录篇) 谁说Win7安装不了Node.js最新版的呢?都2025年,还不更新系统到Win11 vs code远程调试Linux服务器上的php代码 浏览器定制 | Windows11 编译 Chromium 133.0.6885.0(截稿前Chromium最新版之编译篇[一]) 不说是彻底搞懂,至少让你不再惧怕c/c++指针,以及各种奇葩指针变种 解决windows下php8.x及以上版本,在Apache2.4中无法加载CURL扩展的问题 在 Windows8.1 下编译 Chromium (103.0.5060.68 之三)
微信小程序电商实战—首页篇(上)
一个游离于山间之上的江湖漫行者。A jungle wanderer who wanders above the mountain · 2021-03-20 · via 秋码分享

本文将接上一篇,实现首页上半部分,导航滚动与首页轮播图,首页部分分为两篇来讲解

上一篇 微信小程序电商实战—环境搭建篇

1、定义模块与设置头部

首先先在app.json文件中定义首页分类购物车以及我的四个模块。

背景颜色为白色,名称是秋码淘好货

 "pages":[
    "pages/index/index",
    "pages/category/category",
    "pages/cart/cart",
    "pages/personal/personal"
  ],
  "window":{
    "backgroundTextStyle":"light",
    "navigationBarBackgroundColor": "#fff",
    "navigationBarTitleText": "秋码淘好货",
    "navigationBarTextStyle":"black"
  },

2、滑块导航栏

编辑index.wxmlindex.wxss这两个文件

index.wxml

<view class="page">
  <!-- 搜索框 -->
  <view class="search">
    <view class="searchBar">
      <icon class="weui-icon-search" type="search" size="14"></icon>
      <input  class="input" placeholder="大家都在搜" bindtap="entrySearch" disabled />
    </view>
  </view>
  <!-- 导航栏 -->
  <view class="navBar">
      <scroll-view class="navBar-box" scroll-x="true" style="white-space: nowrap; display:flex ">
          <view class="cate-list {{curIndex==index?'on':''}}" wx:for="{{category}}" 
                wx:key="{{item.id}}" data-id="{{item.id}}" data-index="{{index}}" 
                bindtap="navbarTap">{{item.name}}</view>
      </scroll-view>
  </view>
</view>

index.wxss

.page{
  height:100%;
  display:flex;
  flex-direction:column;
  box-sizing:border-box;
  position:relative;
  top:0;
  left:0;
  bottom:0;
  right:0;
  background-color:#f5f8fa;
}

.search{
  background: #fff;
}
.searchBar{
  margin: 20rpx 30rpx;
  border-radius: 30px;
  border:1px solid #f5f5f5;
  background: #f5f5f5;
}
.weui-icon-search{
  margin-left: 15rpx;
  float: left;
}

.navBar{
  height: 60rpx;
  background: #fff;
  border-top: 1px solid #fafafa;
}
.navBar-box{
  width: 100%;
  height: 60rpx;
}
.cate-list{
  display: inline;
  margin: 15rpx 22rpx;
  text-align: center;
  font-size: 14px;
  color: #9d9d9d;
}
.navBar-box .cate-list.on {
  color: #000000;
  font-weight: bold;
}

index.wxml我们使用bindtap进行点击事件监听,设置事件名称为navbarTap并且在index.js里设置这个事件对应的逻辑处理。我们在组件上使用**wx:for控制属性绑定一个数组,即可使用数组中各项的数据重复渲染该组件。默认数组的当前项的下标变量名默认为index,数组当前项的变量名默认为item,想要了解wx:for**可以参考该资料:https://www.w3cschool.cn/weixinapp/weixinapp-list.html

index.js

//导航栏 
// pages/index/index.js
var app = getApp()
Page({
  data:{
    category: [       // 导航栏内容数据
      {name:'热门',id:"remen" },
      {name:'美食',id:'meishi'},
      {name:'居家',id:"jujia"},
      {name:'美妆',id:"meizhuang"},
      {name:'女装', id:"nvzhuang"},
      {name:'母婴',id:"muying"},
      {name:"男装",id:"nanzhuang"},
      {name:"鞋品",id:"xiepin"},
      {name:"箱包",id:"xiangbao"},
      {name:"配饰",id:"peishi"},
      {name:"儿童",id:"ertong"},
      {name:"数码",id:"shuma"},
      {name:"家电",id:"jiadian"},
      {name:"内衣",id:"neiyi"},
      {name:"车品",id:"chepin"},
      {name:"文体",id:"wenti"},
      {name:"宠物",id:"chongwu"},
      {name:"其他",id:"qita"}

    ],
    curIndex: 0,
    detail: [],
    toView: 'remen',
    scroll: true
  },
  navbarTap(e) {
    this.setData({
      curIndex: e.currentTarget.dataset.index?e.currentTarget.dataset.index:0,
      toView: e.currentTarget.dataset.index,
    })
  },

})

保存查看一下: img

3、首页轮播图

在l**index.wxml**添加以下内容

<swiper class="banner" indicator-dots autoplay indicator-active-color="#fbbd08" circular>
    <block wx:for="{{bannerList}}" wx:key="id">
      <swiper-item>
        <image lazy-load src="{{item.img}}"  class="banner_image" />
      </swiper-item>
    </block>
  </swiper>

**index.wxss**添加如下样式

.banner {
  width: 100%;
  display: flex;
  box-sizing: border-box;
  height: 184rpx;
}

.banner_image {
  width: 100%;
  padding: 16rpx 16rpx 12rpx 16rpx;
  display: flex;
  box-sizing: border-box;
  height: 160rpx;
}

**index.js**添加如下内容,在data对象添加一个数组对象。

bannerList:[
      {id:"one",img:"/images/banner/banner-one.png"},
      {id:"teo",img:"/images/banner/banner-two.png"},
      {id:"three",img:"/images/banner/banner-three.jpg"},
      {id:"four",img:"/images/banner/banner-four.jpg"}
    ],

最终实现的效果图如下: img

上一篇 微信小程序电商实战—环境搭建篇