• 小程序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。并设置图片铺满。

    九宫格效果

    域名一样要改变。 

    1. <view class="grid-list">
    2. <view class="grid-item" wx:for="{{gridList}}" wx:key="id">
    3. <image src="{{item.icon}}" mode=""/>
    4. <text>{{item.name}}text>
    5. view>
    6. view>
    1. .grid-list{
    2. display: flex;
    3. flex-wrap:wrap;
    4. border-left: 1rpx solid #efefef;
    5. border-top: 1rpx solid #efefef;
    6. }
    7. .grid-item{
    8. width:33.33%;
    9. height: 200rpx;
    10. display: flex;
    11. flex-direction: column;
    12. align-items: center;
    13. justify-content: center;
    14. border-right: 1rpx solid #efefef;
    15. border-bottom: 1rpx solid #efefef;
    16. box-sizing: border-box;
    17. }
    18. .grid-item image{
    19. width:60rpx;
    20. height: 60rpx;
    21. }
    22. .grid-item text{
    23. font-size: 24rpx;
    24. margin-top: 10rpx;
    25. }

    底层图片布局

    1. <view class="img-box">
    2. <image src="/images/link-01.png" mode="widthFix"/>
    3. <image src="/images/link-02.png" mode="widthFix"/>
    4. view>
    1. .img-box{
    2. display: flex;
    3. padding: 20rpx 10rpx;
    4. justify-content: space-around;
    5. }
    6. .img-box image{
    7. width: 45%;
    8. }

    最终效果和代码

    1. <swiper indicator-dots circular>
    2. <swiper-item wx:for="{{swiperList}}" wx:key="id">
    3. <image src="{{item.image}}">image>
    4. swiper-item>
    5. swiper>
    6. <view class="grid-list">
    7. <view class="grid-item" wx:for="{{gridList}}" wx:key="id">
    8. <image src="{{item.icon}}" mode=""/>
    9. <text>{{item.name}}text>
    10. view>
    11. view>
    12. <view class="img-box">
    13. <image src="/images/link-01.png" mode="widthFix"/>
    14. <image src="/images/link-02.png" mode="widthFix"/>
    15. view>
    1. /* pages/list/list.wxss */
    2. @import "/commons/common.wxss";
    3. swiper{
    4. height: 350rpx;
    5. }
    6. swiper image{
    7. width: 100%;
    8. height: 100%;
    9. }
    10. .grid-list{
    11. display: flex;
    12. flex-wrap:wrap;
    13. border-left: 1rpx solid #efefef;
    14. border-top: 1rpx solid #efefef;
    15. }
    16. .grid-item{
    17. width:33.33%;
    18. height: 200rpx;
    19. display: flex;
    20. flex-direction: column;
    21. align-items: center;
    22. justify-content: center;
    23. border-right: 1rpx solid #efefef;
    24. border-bottom: 1rpx solid #efefef;
    25. box-sizing: border-box;
    26. }
    27. .grid-item image{
    28. width:60rpx;
    29. height: 60rpx;
    30. }
    31. .grid-item text{
    32. font-size: 24rpx;
    33. margin-top: 10rpx;
    34. }
    35. .img-box{
    36. display: flex;
    37. padding: 20rpx 10rpx;
    38. justify-content: space-around;
    39. }
    40. .img-box image{
    41. width: 45%;
    42. }
    1. Page({
    2. /**
    3. * 页面的初始数据
    4. */
    5. data: {
    6. //存放轮播图
    7. swiperList:[],
    8. //存放9宫格
    9. gridList:[]
    10. },
    11. /**
    12. * 生命周期函数--监听页面加载
    13. */
    14. onLoad(options) {
    15. this.getSwiperList(),
    16. this.getGridList()
    17. },
    18. getSwiperList(){
    19. wx.request({
    20. url: 'https://applet-base-api-t.itheima.net/slides',
    21. method:'GET',
    22. success:(res)=>{
    23. console.log(res)
    24. this.setData({
    25. swiperList:res.data
    26. })
    27. }
    28. })
    29. },
    30. getGridList(){
    31. wx.request({
    32. url: 'https://applet-base-api-t.itheima.net/categories',
    33. method:'GET',
    34. success:(res)=>{
    35. console.log(res)
    36. this.setData({
    37. gridList:res.data
    38. })
    39. }
    40. })
    41. }
    42. ,
    43. /**
    44. * 生命周期函数--监听页面初次渲染完成
    45. */
    46. onReady() {
    47. },
    48. /**
    49. * 生命周期函数--监听页面显示
    50. */
    51. onShow() {
    52. },
    53. /**
    54. * 生命周期函数--监听页面隐藏
    55. */
    56. onHide() {
    57. },
    58. /**
    59. * 生命周期函数--监听页面卸载
    60. */
    61. onUnload() {
    62. },
    63. /**
    64. * 页面相关事件处理函数--监听用户下拉动作
    65. */
    66. onPullDownRefresh() {
    67. },
    68. /**
    69. * 页面上拉触底事件的处理函数
    70. */
    71. onReachBottom() {
    72. },
    73. /**
    74. * 用户点击右上角分享
    75. */
    76. onShareAppMessage() {
    77. }
    78. })

    总结

  • 相关阅读:
    星宸科技SSC369G 双4K高性价比AI IPC方案
    如何实现redis的高可用?
    一、CSS弹性布局[弹性盒子、弹性元素]
    科学素养题(2022年2月-2022年10月)
    [Shell详解-4]:echo命令、printf命令
    vue3对象reactive()数据改变页面不刷新
    数据结构的结构复杂度你了解么
    Spring核心思想
    电动汽车有序无序充放电的优化调度附matlab代码
    UE5、CesiumForUnreal实现建筑白模生成及白模美化功能
  • 原文地址:https://blog.csdn.net/m0_62327332/article/details/134095327