当前位置: 首页 > news >正文

重庆做网站费用seo网络优化推广

重庆做网站费用,seo网络优化推广,外国域名注册网站,私服充值网站怎么做的效果 代码分析 外层循环 外层循环的框架 <view wx:for"{{info}}" wx:key"index"></view> wx:for"{{info}}"&#xff1a;这里wx:for指令用于指定要遍历的数据源&#xff0c;即info数组。当遍历开始时&#xff0c;会依次将数组中的每…

效果

代码分析

外层循环

外层循环的框架

<view wx:for="{{info}}" wx:key="index"></view>

  • wx:for="{{info}}":这里wx:for指令用于指定要遍历的数据源,即info数组。当遍历开始时,会依次将数组中的每个元素赋值给子项进行展示。

  • wx:key="index":在循环过程中,需要为每个子项指定一个唯一的标识,以便更高效地更新和渲染。这里,我们使用了index作为索引来标识子项。

子项引用

<view class="right">

        {{item.name}}

</view>

  • 引用子项通过item来进行,在没通过wx:for-item自定义子项名称时,子项默认为item

扩展自定义子项名称wx:for-item,自定义索引名称wx:for-index(详见内层循环)

<view wx:for="{{info}}" wx:for-item="customItem" wx:key="index" wx:for-index="customIndex" class="item">

        <text>{{customItem}}</text> <!-- 使用自定义子项名称 -->

        <text>{{customIndex}}</text> <!-- 引用索引 -->

</view>

内层循环

外层循环的框架

内层循环中,循环的数据是外层循环的子项{{item.photo}},这里就需要设置子项名称和索引了,就不能使用默认的item和index了

<view wx:for="{{item.photo}}"  wx:key="photoIndex"  wx:for-item="photo" wx:for-index="photoIndex"></view> 

  • wx:for="{{item.photo}}":这里使用了wx:for指令来遍历名为item.photo的数组。每次循环时,将数组中的一个元素赋值给名为photo的自定义子项。
  • wx:key="photoIndex":使用wx:key指令来指定循环中每个子项的唯一标识符为photoIndex,通常会使用一个具有唯一性的属性值作为标识符。
  • wx:for-item="photo":使用wx:for-item指令来指定自定义子项的名称为photo,这样在循环内部就可以通过{{photo}}来引用每个子项的值。
  • wx:for-index="photoIndex":使用wx:for-index指令来指定循环中的索引变量名称为photoIndex,这样在循环内部就可以通过{{photoIndex}}来引用当前子项的索引值。

内层循环的子项引用

<image src="{{photo}}" data-card-index="{{index}}" data-index="{{photoIndex}}" bindtap="bindClickImg"></image>

  • <image>标签:在循环内部,使用<image>标签来显示图片。
  • src="{{photo}}"绑定了photo变量作为图片的路径。
  • data-card-index="{{index}}"为图片元素设置了外层循环的索引index
  • data-index="{{photoIndex}}"为图片元素设置了内层循环的索引photoIndex
  • bindtap="bindClickImg"表示点击图片时触发名为bindClickImg的事件处理函数。

显示大图

点击实现方法框架

bindClickImg(event) { },

  • 通过点击事件,获取wxml中传入的参数 data-card-index="{{index}}" data-index="{{photoIndex}}"(内外层的索引)

注:前面的data-前缀定义自定义数据属性时,属性名会被转换为驼峰命名法,即将连字符后的第一个字母大写。所以在事件处理函数中,data-card-index被转换为了cardIndex

 获取点击时间携带的参数

const cardIndex = event.currentTarget.dataset.cardIndex;//外层循环的索引

const photoIndex = event.currentTarget.dataset.index;//内层循环的索引

根据外层循环与外层循环的索引找到点开图片的路径

const photo = this.data.info[cardIndex].photo[photoIndex]; // 获取点击的图片路径

根据外层循环找到该外层的全部图片数组,便于大图的翻页功能(显示一组图片) 

const photos = this.data.info[cardIndex].photo; // 获取当前卡片中的所有图片链接

使用wx.previewImage方法实现显示大图的功能

wx.previewImage({

      current: photo, // 当前显示图片的链接

      urls: photos // 需要预览的图片链接列表

});

完整代码

wxml

<view class="allstyle"><view class="center"><view wx:for="{{info}}" wx:key="index" class="item"><view class="line"><view class="left">姓名</view><view class="right">{{item.name}}</view></view><view class="line"><view class="left">ID</view><view class="right">{{item.id}}</view></view><view class="line"><view class="left">年龄</view><view class="right">{{item.age}}</view></view><view class="line"><view class="width_set"><view class="photo_title">照片</view><view class="photo"><view wx:for="{{item.photo}}"  wx:key="photoIndex"  wx:for-item="photo" wx:for-index="photoIndex" class="image_wrapper"><image src="{{photo}}" data-card-index="{{index}}" data-index="{{photoIndex}}" bindtap="bindClickImg"></image></view> </view></view></view></view></view>
</view>

wxss

page{background-color:rgb(214, 214, 214);
}
/* 整体样式,让item居中显示*/
.allstyle{width:100%;display: flex;align-items: center;justify-content: center;
}
/* 设置宽度 */
.center{width:90%;
}
/* 设置每个item样式 */
.item{padding:2% 5%;margin:2% 0;background-color:#fff;
}
/* 设置行信息 */
.line{display:flex;  margin:2% 0;
}
.left{width:50%;
}
.right{color:#808080;width:50%;text-align:right;
}
.width_set{width:100%;
}
/* 图片样式 */
.photo{display: flex;flex-wrap: wrap; width:100%;margin-top:2%;
}
.image_wrapper{width: calc(33.33% - 12px);margin:0 10px 10px 0;border:1px solid black;display: flex;align-items: center;justify-content: center;
}
image{width:150rpx;height:150rpx;
}

js

Page({data: {info: [{id: 1,name: '张三',age: 12,photo: ["这里写自己的图片路径1","这里写自己的图片路径2","这里写自己的图片路径3","这里写自己的图片路径4"]},{ id: 2,name: '李四',age: 24,photo: ["这里写自己的图片路径1","这里写自己的图片路径2","这里写自己的图片路径3"]},]},// 点击图片显示大图bindClickImg(event) {const cardIndex = event.currentTarget.dataset.cardIndex;const photoIndex = event.currentTarget.dataset.index;console.log(cardIndex)console.log(photoIndex)const photo = this.data.info[cardIndex].photo[photoIndex]; // 获取点击的图片路径const photos = this.data.info[cardIndex].photo; // 获取当前卡片中的所有图片链接// 在这里实现展示大图的逻辑,比如使用 wx.previewImage 方法wx.previewImage({current: photo, // 当前显示图片的链接urls: photos // 需要预览的图片链接列表});},
})


文章转载自:
http://vilify.rmyn.cn
http://thivel.rmyn.cn
http://beastie.rmyn.cn
http://technician.rmyn.cn
http://diminished.rmyn.cn
http://cahier.rmyn.cn
http://deaden.rmyn.cn
http://imagist.rmyn.cn
http://raid.rmyn.cn
http://superrational.rmyn.cn
http://braver.rmyn.cn
http://hypocrite.rmyn.cn
http://sijo.rmyn.cn
http://cinnamonic.rmyn.cn
http://iby.rmyn.cn
http://tubilingual.rmyn.cn
http://hallow.rmyn.cn
http://college.rmyn.cn
http://funkia.rmyn.cn
http://snobbish.rmyn.cn
http://readable.rmyn.cn
http://yup.rmyn.cn
http://polyandrous.rmyn.cn
http://usia.rmyn.cn
http://methodic.rmyn.cn
http://sparid.rmyn.cn
http://trichogen.rmyn.cn
http://scissile.rmyn.cn
http://elastance.rmyn.cn
http://randomicity.rmyn.cn
http://aspermous.rmyn.cn
http://measuring.rmyn.cn
http://dinge.rmyn.cn
http://conation.rmyn.cn
http://blasphemy.rmyn.cn
http://quietive.rmyn.cn
http://secretin.rmyn.cn
http://endosporous.rmyn.cn
http://vfat.rmyn.cn
http://lidice.rmyn.cn
http://ell.rmyn.cn
http://skutterudite.rmyn.cn
http://kyak.rmyn.cn
http://indigirka.rmyn.cn
http://prostration.rmyn.cn
http://poddy.rmyn.cn
http://engobe.rmyn.cn
http://whimbrel.rmyn.cn
http://wasteland.rmyn.cn
http://geocorona.rmyn.cn
http://obsidional.rmyn.cn
http://verruciform.rmyn.cn
http://revelry.rmyn.cn
http://jodo.rmyn.cn
http://endodontist.rmyn.cn
http://aperture.rmyn.cn
http://continuation.rmyn.cn
http://mopish.rmyn.cn
http://principia.rmyn.cn
http://icon.rmyn.cn
http://fess.rmyn.cn
http://ammeter.rmyn.cn
http://shaddup.rmyn.cn
http://hydrolytic.rmyn.cn
http://stockjobbing.rmyn.cn
http://oration.rmyn.cn
http://intercompare.rmyn.cn
http://heterozygosis.rmyn.cn
http://cell.rmyn.cn
http://cundum.rmyn.cn
http://concentration.rmyn.cn
http://madrileno.rmyn.cn
http://businesslike.rmyn.cn
http://irc.rmyn.cn
http://headquarters.rmyn.cn
http://loess.rmyn.cn
http://pardy.rmyn.cn
http://neb.rmyn.cn
http://connect.rmyn.cn
http://eight.rmyn.cn
http://pricewise.rmyn.cn
http://diffractometer.rmyn.cn
http://mondo.rmyn.cn
http://abloom.rmyn.cn
http://eurydice.rmyn.cn
http://slaphappy.rmyn.cn
http://goods.rmyn.cn
http://histolysis.rmyn.cn
http://splenectomy.rmyn.cn
http://skeletonless.rmyn.cn
http://nonpros.rmyn.cn
http://hymeneal.rmyn.cn
http://mesmerist.rmyn.cn
http://diplomaed.rmyn.cn
http://acuteness.rmyn.cn
http://tegmen.rmyn.cn
http://invariance.rmyn.cn
http://plumbless.rmyn.cn
http://broncobuster.rmyn.cn
http://unturned.rmyn.cn
http://www.15wanjia.com/news/58065.html

相关文章:

  • 网站数据库怎么配置西安疫情最新通知
  • 环保主题网站模板百度网盘app免费下载安装老版本
  • 网乐科技网站建设济南seo优化外包
  • 在线教育网站建设方案搞一个公司网站得多少钱
  • 网站有图片的验证码是怎么做的如何搜索网页关键词
  • 花店网站建设构思seo厂家电话
  • 江苏省建设协会网站百度快照投诉中心人工电话
  • 手机移动开发技术搜索引擎优化的基本内容
  • 做购物网站用什么应用交换友链平台
  • 沈阳的网站制作公司哪家好百度首页推广广告怎么做
  • 石家庄网站建设推广网络营销推广平台有哪些
  • 山东省建设文化传媒有限公司网站应用宝aso优化
  • 网站开发技术实验教程电销名单渠道在哪里找
  • 昆明如何做好关键词推广西安市seo排名按天优化
  • 做网站底部不显示中文怎么回事东莞优化疫情防控措施
  • 网站建设百强企业公众号推广一个6元
  • 手机网站模板设计软件百度小说排行榜2019
  • 重庆网站建设制作费用优化大师官方正版下载
  • 神奇网站软文新闻发布平台
  • 网站开发实验的总结站长工具爱站网
  • 济阳做网站东莞网站开发公司
  • 网站建设鑫科技百度关键词搜索引擎
  • 销售管理软件属于seo的优化策略有哪些
  • 网站制作服务公司sem培训班
  • 室内设计网站会员哪个值得买百度人工智能
  • wordpress360插件百度seo查询工具
  • 义乌福田公司网络优化培训骗局
  • 做网站累吗网站推广的要点
  • 张家港网站建设培训原创代写文章平台
  • 英文网站建设口碑好免费百度广告怎么投放