微信小程序—day02

摘要:
全局配置在app.json中,小程序是全局配置的。以for循环的形式将数据数组中的数据传输到wxml。这是我对列表渲染的理解。Wxml代码:margin-bottom:10px;}。导航项{25%;填充:10px;显示:内联块;文本对齐:居中;框大小:边框;}。iconPic{88rpx;高度:88rpx,}。iconTitle{color:#666;font-size:14px;}主页的顶部和中部已完成:text组件官方文档image组件官方文档在这里使用mode属性中的widthFix,但图像的宽度应设置为wxss。Wxml代码:食物推荐{item.title}}wxss代码:。文章{background-color:#fff;padding:10px;}。文章顶部{文本对齐:中心;颜色:rgb;}。文章项{padding bottom:10px;padding top:10px;border bottom style:double;border 3px;border color:#A1A7AD;}。文章图片{100%;}。articleTitle{font-size:16px;color:#A1A7AD;}因为两个跳转页面的布局相同,所以只显示一个。Wxml代码:title{position:relative;text align:center;font size:26px;color:#8CBEF5;padding:15px;margin-bottom:20px;}。标题底部{padding:20px;}。标题底部:在{content:“”之后;位置:绝对;左:50px;顶部:自动;底部:0;右:自动;高度:5px;275px;背景色:#32b66b;}。text{padding:10px;font-size:18px;line-height:1.5;}css:after中的伪类用于控制边框的长度。

全局配置

在app.json中,对小程序进行全局配置。官方文档

tabBar是对底部/顶部导航栏的配置,图片的icon 大小限制为40kb,建议尺寸为 81px * 81px

阿里矢量图网站,找到图片,存放到images文件夹中

app.json中的tabBar代码:

"tabBar": {
    "list": [{
      "pagePath": "pages/home/home",
      "text": "主 页",
      "iconPath": "images/home.png",
      "selectedIconPath": "images/home-red.png"
    },{
      "pagePath": "pages/user/user",
      "text": "我 的",
      "iconPath": "images/user.png",
      "selectedIconPath": "images/user-red.png"
      }
    ]
  }

我的底部导航栏:

微信小程序—day02第1张

swiper滑块视图

 通过swiper,制作一个轮播图。官方文档

轮播图位于主页的顶部,wxml代码:

<view class='top-swiper'>
<swiper autoplay='true' indicator-dots='true' indicator-color='#fff' indicator-active-color='#8CBEF5' circular='true'>
  <swiper-item wx:for="{{banners}}">
    <image src='{{item.imgUrl}}'></image>
  </swiper-item>
</swiper>
</view>

wxss代码:

swiper-item image {
   100%;
  height: 100%;
}

图片宽高都设为100%,相当于拉伸填充;虽然图片会变形,但无伤大雅。

列表渲染

列表渲染,其实就是for循环。官方文档

页面数据是存放在.js文件,里面的Page.data之内。

将data中的数组之内的数据,以for循环的形式传递到wxml之中,这是我理解的列表渲染。

通过列表渲染,完成了主页的中间部分。

wxml代码:

<view class='navs'>
<view class="nav-item" wx:for="{{icons}}">
  <view>
    <image class='iconPic' src='{{item.imgUrl}}'></image>
  </view>
  <text class='iconTitle'>{{item.name}}</text>
</view>
</view>

wxss代码:

.navs {
  display: flex;
   100%;
  flex-wrap: wrap;
  background-color: #fff;
  margin-bottom: 10px;
}
.nav-item {
   25%;
  padding: 10px;
  display: inline-block;
  text-align: center;
  box-sizing: border-box;
}
.iconPic {
   88rpx;
  height: 88rpx;
}
.iconTitle {
  color: #666;
  font-size: 14px;
}

主页的顶部与中部就完成了:

微信小程序—day02第2张

text组件

官方文档

 微信小程序—day02第3张

image组件

官方文档

这里用到了mode属性中的widthFix,但要在wxss中对图片的宽度width进行设置。

navigator组件

官方文档

navigator组件用于页面的跳转。

微信小程序—day02第4张

利用navigator组件,编写主页底部,并完成底部文章的跳转页面。

 wxml代码:

<view class='article'>
  <view class='article-top'>食物推荐</view>
  <view class='article-item' wx:for="{{article}}">
    <navigator url='{{item.link}}' open-type='navigate'>
      <image class='articlePic' src='{{item.imgUrl}}' mode='widthFix'></image>
      <view class='articleTitle'>{{item.title}}</view>
    </navigator>
  </view>
</view>

wxss代码:

.article {
  background-color: #fff;
  padding: 10px;
}
.article-top {
  text-align: center;
  color: rgb(116, 230, 144);
}
.article-item {
  padding-bottom: 10px;
  padding-top: 10px;
  border-bottom-style: double;
  border- 3px;
  border-color: #A1A7AD;
}
.articlePic {
   100%;
}
.articleTitle {
  font-size: 16px;
  color: #A1A7AD;
}

 因为两个跳转的页面布局相同,只呈现一个的。

 wxml代码:

<view>
  <image class='img' src='{{article.imgUrl}}' mode='widthFix'></image>
</view>

<view>
  <view class='title'>
    <view class='title-bottom'>{{article.title}}</view>
  </view>
  <view class='text'>
    <text decode='true'>{{article.content}}</text>
  </view>
</view>

wxss代码:

.img {
   100%;
}
.title {
  position: relative;
  text-align: center;
  font-size: 26px;
  color: #8CBEF5;
  padding: 15px;
  margin-bottom: 20px;
}
.title-bottom {
  padding: 20px;
}
.title-bottom:after {
  content: "";
  position: absolute;
  left: 50px;
  top: auto;
  bottom: 0;
  right: auto;
  height: 5px;
   275px;
  background-color: #32b66b;
}
.text {
  padding: 10px;
  font-size: 18px;
  line-height: 1.5;
}

这里用到了css中的伪类  :after ,来控制边框的长短。

参考了博客:https://blog.csdn.net/Colossalis_c/article/details/71216339

最终完成后的主页与跳转页:

微信小程序—day02第5张微信小程序—day02第6张        微信小程序—day02第7张

scroll-view可滚动视图区域

 官方文档

scroll-x属性设为true,允许横向滚动。scroll-left设置横向滚动条位置。

滚动区域基本编写完毕。编写过程中,出现滚动区域无法拖动的问题,待明天解决。

免责声明:文章转载自《微信小程序—day02》仅用于学习参考。如对内容有疑问,请及时联系本站处理。

上篇mysql-community-server-5.7.24 &amp;amp; 5.7.31 (5.6.35 升级到 5.7.24)kali学习笔记(一):虚拟机安装好kali后应进行的配置下篇

宿迁高防,2C2G15M,22元/月;香港BGP,2C5G5M,25元/月 雨云优惠码:MjYwNzM=

相关文章

微信小程序知识点总结--组件

一、部分常用组件 1、scroll-view可滚动视图区域:   <scroll-view>标签必须设置scroll-x/scroll-y属性,否则不能实现滚动效果 css设置:<scroll-view>标签可以设置white-space:nowrap,子元素设置display:inline-block(如子元素中有文字需要换行,则...

什么是盒模型?

  css盒模型是在网页设计中经常用到的css技术所使用的一种思维模型!   在网页中,css盒模型主要4个部分组成,有Content(内容)-Margin(外边距)-Border(边框)-Padding(内边距)       在网页中,一个元素占有空间的大小由几个部分构成,其中包括元素的内容,元素的补白,元素的边框,元素的边界四个部分。这四个部分占有的空...

【转】CSS浏览器兼容性与解析问题终极归纳

1.怪异模式问题:漏写DTD声明,Firefox仍然会按照标准模式来解析网页,但在IE中会触发怪异模式。为避免怪异模式给我们带来不必要的麻烦,最好养成书写DTD声明的好习惯。 2.IE6双边距问题:在IE6下,如果对元素设置了浮动,同时又设置了margin-left或margin-right,margin值会加倍。例如: HTML: <div cla...

Asp.net Core 微信小程序支付

最近要做一个微信小程序支付的功能 在网上找了一下 .net Core做微信支付的博客 和 demo 几乎没有 自己研究了好几天 参考了 很多 大牛的博客 勉强做出来了 因为参数都没有 比如 opid 小程序域名 所以只是简单的测了一下 模拟了微信支付的回调请求 后续等项目上线 会回来填坑的 第一次看小程序支付的api文档 看得我一脸懵逼 现在简单说一下吧...

offsetLeft, offsetTop以及postion().left , postion().top有神马区别

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml">...

小程序初识

1.rpx 是微信小程序解决自适应屏幕尺寸的尺寸单位。微信小程序规定屏幕的宽度为750rpx。 无论是在iPhone6上面还是其他机型上面都是750rpx的屏幕宽度,拿iPhone6来讲,屏幕宽度为375px,把它分为750rpx后, 1rpx = 0.5px。 微信小程序同时也支持rem尺寸单位, rem 规定屏幕的宽度为20rem, 所以 1rem...