当前位置:网站首页>微信小程序中的列表渲染
微信小程序中的列表渲染
2022-06-25 03:44:00 【richest_qi】
小程序项目
代码涉及的主要文件有:
- app.json
- pages/index/index.wxml
- pages/index/index.wxss
- pages/index/index.js

app.json
{
"pages": [
"pages/index/index"
],
"window": {
"navigationBarBackgroundColor": "#971a22",
"navigationBarTitleText": "首页",
"navigationBarTextStyle": "white"
},
"style": "v2",
"sitemapLocation": "sitemap.json"
}
pages/index/index.wxml
<view class="container">
<swiper class="bannerContainer" autoplay indicator-dots indicator-color="#971a22" indicator-active-color="ivory">
<swiper-item wx:for="{
{bannerList}}" wx:key="id">
<image src="{
{item.pic}}"></image>
</swiper-item>
</swiper>
<scroll-view class="recommendList" enable-flex scroll-x>
<view class="recommendItem" wx:for="{
{recommendList}}" wx:key="id">
<image src="{
{item.picUrl}}"></image>
<view class="title">{
{item.title}}</view>
</view>
</scroll-view>
</view>
pages/index/index.wxss
.bannerContainer image{
width: 100%;
height: 300rpx;
}
.recommendList{
display: flex;
padding: 20rpx;
}
.recommendList image{
width: 200rpx;
height: 200rpx;
border-radius: 10rpx;
margin-right: 10rpx;
}
.recommendList .title{
font-size: 26rpx;
display: -webkit-box;
overflow: hidden;
text-overflow:ellipsis;
-webkit-box-orient: vertical;
-webkit-line-clamp: 2;
}
pages/index/index.js
Page({
data:{
bannerList:[],
recommendList:[]
},
onLoad(){
this.getBannerList();
this.getRecommendList();
},
getBannerList(){
const result = [
{
pic: "http://p1.music.126.net/N-7H0QxkjcnqNfQo7Prx9g==/109951167582698387.jpg", id: 146917329},
{
pic: "http://p1.music.126.net/CRkjYtGzVn927GVZFNcykQ==/109951167582707134.jpg", id: 146972047},
{
pic: "http://p1.music.126.net/UCpvQwegTjx-_ecHDDrViQ==/109951167583920308.jpg", id: 1958588078},
{
pic: "http://p1.music.126.net/5hxwliN1A-ocfo1y8Rl-LA==/109951167583325800.jpg", id: 146939174},
{
pic: "http://p1.music.126.net/i9A9PG9tvDqkuRekCR8EgQ==/109951167583029047.jpg", id: 1957532468},
{
pic: "http://p1.music.126.net/es8XZbDQWrNjA_VyW7XJeQ==/109951167583025966.jpg", id: 146848766},
{
pic: "http://p1.music.126.net/7YCWTLNpIqzdaYD_WrB6qA==/109951167583039220.jpg", id: 146627102},
{
pic: "http://p1.music.126.net/u2Y1A90S5fh3R4qVhKrIGQ==/109951167582728056.jpg", id: 223052482},
{
pic: "http://p1.music.126.net/Jn1zsklqb_qmPfoJsooJ2Q==/109951167582726188.jpg", id: 1957961053},
{
pic: "http://p1.music.126.net/lsKgZUDW-4C8SRbQciZvmA==/109951167583045066.jpg", id: 1955958008}
]
this.setData({
bannerList:result})
},
getRecommendList(){
const result = [
{
id: 494479726, picUrl: "https://p2.music.126.net/58ox3zVEmosSrdLaKj6x5w==/109951162827155600.jpg", title: "后摇MV | 原来后摇也能视觉化"},
{
id: 135595185, picUrl: "https://p2.music.126.net/11ZHf0G9FQzWNi-8sFzCmw==/109951164541050373.jpg", title: "Acid Jazz酸爵士—爵士乐中的“酸性”融合"},
{
id: 114846926, picUrl: "https://p2.music.126.net/GTf1b1G2dAs1SleurIfcJg==/3399689953594431.jpg", title: "歌名后缀大科普"},
{
id: 113780871, picUrl: "https://p2.music.126.net/qxUWSKhrd1UWME8oAYTMFQ==/109951164497486331.jpg", title: "「Cool Jazz」冷爵士让你全身心放松"},
{
id: 2962407224, picUrl: "https://p2.music.126.net/NW1GEN3sruiLpT4AZrdDFw==/109951165669533032.jpg", title: "『英伦女声』遗世而独立的不列颠玫瑰"},
{
id: 2107922801, picUrl: "https://p2.music.126.net/b--QkIcFfdxz_DryW55ZfA==/109951163165101034.jpg", title: "声光美学 I 经典电影中的古典配乐集"},
{
id: 78669437, picUrl: "https://p2.music.126.net/AfN_yyi-fQe8POTMKJFjAA==/7957165650297535.jpg", title: "美剧中的神级插曲"},
{
id: 3116763088, picUrl: "https://p2.music.126.net/MSom1XSXqt5K9ArZlJ29CQ==/109951164608648583.jpg", title: "音乐的力量 I 文艺复兴时期的世俗情歌"},
{
id: 101354498, picUrl: "https://p2.music.126.net/dmj9iqz8MsD_sCd1xBF0WA==/7918682744429845.jpg", title: "时尚运动•必备节奏"},
{
id: 739403485, picUrl: "https://p2.music.126.net/RPilW2ADtU91CK3qkVPizA==/18720284976441185.jpg", title: "弦外有声——活力小提琴"}
]
this.setData({
recommendList:result})
}
})
小结
记住四个指令就行:
wx:for,绑定一个数组。wx:key。唯一的字符串或数值。要么是数组元素item的某个属性,要么是*this(此时,item本身是一个唯一的字符串或数值)。wx:for-item。默认数组当前元素的变量名为item,可以使用wx:for-item重新指定当前元素的变量名。wx:for-index。默认数组当前元素的下标变量名为index,可以使用wx:for-index重新指定当前元素的下标变量名。
相关链接
边栏推荐
- TC object structure and abbreviation
- Dr. Sun Jian was commemorated at the CVPR conference. The best student thesis was awarded to Tongji Ali. Lifeifei won the huangxutao Memorial Award
- IE寿终正寝,网友们搞起了真·墓碑……
- 【组队学习】SQL编程语言笔记——Task04
- Tianshu night reading notes - 8.4 diskperf disassembly
- Russian Airi Research Institute, etc. | SEMA: prediction of antigen B cell conformation characterization using deep transfer learning
- Jilin University 22 spring March "official document writing" assignment assessment-00029
- Sun Wu plays Warcraft? There is a picture and a truth
- Tensorflow, danger! Google itself is the one who abandoned it
- 数学分析_笔记_第3章:极限
猜你喜欢

可能是拿反了的原因

老叶的祝福

AI越进化越跟人类大脑像!Meta找到了机器的“前额叶皮层”,AI学者和神经科学家都惊了...
佐喃社区

TensorFlow,危!抛弃者正是谷歌自己

Does it count as staying up late to sleep at 2:00 and get up at 10:00? Unless you can do it every day

(超详细onenet TCP协议接入)arduino+esp8266-01s接入物联网平台,上传实时采集数据/TCP透传(以及lua脚本如何获取和编写

《悉达多》:一生之书,可以时常反刍

Redis related-03

严重的PHP缺陷可导致QNAP NAS 设备遭RCE攻击
随机推荐
Peking University has a new president! Gongqihuang, academician of the Chinese Academy of Sciences, took over and was admitted to the Physics Department of Peking University at the age of 15
Comprehensive operation of financial risk management X of Dongcai
zabbix的安装避坑指南
The programmer reality show is coming again! Hulan, as the host, carried the lamp to fill the knowledge. The SSS boss had a bachelor's degree in pharmacy. Zhu Jun and Zhang Min from Tsinghua joined th
现在,耳朵也要进入元宇宙了
windows 2003 64位系统php运行报错:1% 不是有效的 win32 应用程序
MySQL modifies and deletes tables in batches according to the table prefix
虽然传统意义上的互联网早已不复存在,但这并不代表互联网早已消失不再
Oracle-sqlload import external data details
[harmony OS] [ark UI] basic ETS context operations
Now, the ear is going into the metauniverse
Qt编译数据库插件通用步骤说明
Sleep more, you can lose weight. According to the latest research from the University of Chicago, sleeping more than 1 hour a day is equivalent to eating less than one fried chicken leg
Trading system development (IV) - trading counter system
OpenSUSE installation pit log
BGP biplane architecture
香蕉为什么能做随机数生成器?因为,它是水果界的“辐射之王”
Dr. Sun Jian was commemorated at the CVPR conference. The best student thesis was awarded to Tongji Ali. Lifeifei won the huangxutao Memorial Award
[harmony OS] [arkui] ETS development graphics and animation drawing
马斯克被诉传销索赔2580亿美元,台积电公布2nm制程,中科院发现月壤中含有羟基形式的水,今日更多大新闻在此...