小程序day02

目标

WXML模板语法

数据绑定

事件绑定

那麽問題來了,一次點擊會觸發兩個組件事件的話,該怎么阻止事件冒泡呢?

文本框和data的双向绑定

注意点:

只在标签里面用value="{{info}}",只会是info到文本框的单向绑定,必须在触发函数里面实现从文本框到info的绑定。然后才能像vue的v-model一样实现双向绑定。

条件渲染

相当于vue里面template.

列表渲染

这里也可以遍历对象数组。

总结: 有id用id当做key值,没有的话就拿index当做key值。

WXSS模板样式

RPX

样式导入

全局样式和局部样式

这里权重没有详细讲是什么东西。

全局配置

tabBar

页面配置

网络数据请求

案例-本地生活(首页)

该语句的作用是隐藏未校验域名的黄色警告。

接口的域名部分改成了https://applet-base-api-t.itheima.net

获取轮播图数据

然后赋值给了一个数组

渲染轮播图

使用获取到的数据渲染图片,并加上圆点效果和的衔接效果.

样式设置了轮播图区域的高度为350rpx。并设置图片铺满。

九宫格效果

域名一样要改变。

html 复制代码
<view class="grid-list">
  <view class="grid-item" wx:for="{{gridList}}" wx:key="id">
  <image src="{{item.icon}}" mode=""/>
  <text>{{item.name}}</text>
  </view>
</view>
css 复制代码
.grid-list{
  display: flex;
  flex-wrap:wrap;
  border-left: 1rpx solid #efefef;
  border-top: 1rpx solid #efefef;
}

.grid-item{
  width:33.33%;
  height: 200rpx;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  border-right: 1rpx solid #efefef;
  border-bottom: 1rpx solid #efefef;
  box-sizing: border-box;
}
.grid-item image{
  width:60rpx;
  height: 60rpx;
}
.grid-item text{
   font-size: 24rpx;
   margin-top: 10rpx;
}

底层图片布局

html 复制代码
<!--图片区域-->
<view class="img-box">
<image src="/images/link-01.png" mode="widthFix"/>
<image src="/images/link-02.png" mode="widthFix"/>
</view>
css 复制代码
.img-box{
  display: flex;
  padding: 20rpx 10rpx;
  justify-content: space-around;
}
.img-box image{
  width: 45%;
}

最终效果和代码

html 复制代码
<swiper indicator-dots circular>
<swiper-item wx:for="{{swiperList}}" wx:key="id">
<image src="{{item.image}}"></image>
</swiper-item>
</swiper>

<view class="grid-list">
  <view class="grid-item" wx:for="{{gridList}}" wx:key="id">
  <image src="{{item.icon}}" mode=""/>
  <text>{{item.name}}</text>
  </view>
</view>


<!--图片区域-->
<view class="img-box">
<image src="/images/link-01.png" mode="widthFix"/>
<image src="/images/link-02.png" mode="widthFix"/>
</view>
css 复制代码
/* pages/list/list.wxss */
@import "/commons/common.wxss";

swiper{
  height: 350rpx;
}
swiper image{
  width: 100%;
  height: 100%;
}

.grid-list{
  display: flex;
  flex-wrap:wrap;
  border-left: 1rpx solid #efefef;
  border-top: 1rpx solid #efefef;
}

.grid-item{
  width:33.33%;
  height: 200rpx;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  border-right: 1rpx solid #efefef;
  border-bottom: 1rpx solid #efefef;
  box-sizing: border-box;
}
.grid-item image{
  width:60rpx;
  height: 60rpx;
}
.grid-item text{
   font-size: 24rpx;
   margin-top: 10rpx;
}
.img-box{
  display: flex;
  padding: 20rpx 10rpx;
  justify-content: space-around;
}
.img-box image{
  width: 45%;
}
javascript 复制代码
Page({

  /**
   * 页面的初始数据
   */
  data: {
    //存放轮播图
    swiperList:[],
    //存放9宫格
    gridList:[]
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad(options) {
    this.getSwiperList(),
    this.getGridList()
  },
  getSwiperList(){
    wx.request({
      url: 'https://applet-base-api-t.itheima.net/slides',
      method:'GET',
      success:(res)=>{
        console.log(res)
        this.setData({
          swiperList:res.data
        })
      }
    })
  },
  getGridList(){
    wx.request({
      url: 'https://applet-base-api-t.itheima.net/categories',
      method:'GET',
      success:(res)=>{
        console.log(res)
        this.setData({
          gridList:res.data
        })
      }
    })
  }
  ,
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady() {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow() {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide() {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload() {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh() {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom() {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage() {

  }
})

总结

相关推荐
三天不学习2 小时前
使用Cursor + Devbox + Uniapp 一站式AI编程开发移动端(App、H5、小程序)
小程序·uni-app·ai编程
刘大浪14 小时前
uniapp 小程序 学习(一)
学习·小程序·uni-app
炫彩@之星1 天前
微信小程序渗透测试指北(附案例)
微信小程序·小程序
—Qeyser1 天前
让 Deepseek 写电器电费计算器小程序
ai·chatgpt·小程序·deepseek
27669582921 天前
朴朴超市小程序 sign-v2 分析
java·python·小程序·逆向分析·朴朴超市·sign-v2·朴朴
说私域2 天前
新零售视域下实体与虚拟店融合的技术逻辑与商业模式创新——基于开源AI智能名片与链动2+1模式的S2B2C生态构建
人工智能·小程序·开源·零售
java1234_小锋2 天前
[免费]微信小程序音乐播放器(爬取网易云音乐数据)(node.js后端)【论文+源码】
微信小程序·小程序·node.js·音乐播放器·网易云音乐
野盒子2 天前
前端面试题 微信小程序兼容性问题与组件适配策略
前端·javascript·面试·微信小程序·小程序·cocoa
胡斌附体2 天前
uniapp小程序不支持动态组件问题
小程序·uni-app·if-else·动态组件·不支持·编译异常
小妖6662 天前
uni-app 小程序 Cannot read property ‘addEventListener‘ of undefined, mounted hook
小程序·uni-app