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

成都市建设网站公司人民日报今日头条新闻

成都市建设网站公司,人民日报今日头条新闻,上海网站设计公司推荐亿企邦,wap网站编辑器web-app uniapp监测屏幕大小的变化对数组一行展示数据作相应处理 1.uni.getSystemInfoSync().screenWidth; 获取屏幕宽度 2.uni.onWindowResize() 实时监测屏幕宽度变化 3.根据宽度的大小拿到每行要展示的数量itemsPerRow 4.为了确保样式能够根据 items…

web-app uniapp监测屏幕大小的变化对数组一行展示数据作相应处理
在这里插入图片描述
1.uni.getSystemInfoSync().screenWidth; 获取屏幕宽度
2.uni.onWindowResize() 实时监测屏幕宽度变化
3.根据宽度的大小拿到每行要展示的数量itemsPerRow
4.为了确保样式能够根据 itemsPerRow 动态调整,可以使用 CSS 变量或动态类。width: calc((100% - 40rpx * (itemsPerRow - 1)) / itemsPerRow);

<template><view class="index"><!-- list表单 --><view class="activityList"><view class="innerContent"><!-- conent-list --><view class="content-list"><view class="list-row" v-for="(row, rowIndex) in groupedCollectionList" :key="rowIndex"><view class="list-item" v-for="(item, index) in row" :key="index" @click="goDetail(item)"><view class="item-left" v-if="item.picture"><image class="img" :src="item.picture" /></view><view class="item-right"><view class="title space" v-if="item.name.length > 10">{{ item.name.slice(0, 10) }}...</view><view class="title space" v-else>{{ item.name }}</view><view class="title space">{{ item.createdTime }}</view></view></view></view></view></view></view></view></template><script>
export default {data() {return {list:[],itemsPerRow:1,// 默认每行显示1个};},computed: {// 在 computed 中添加 groupedCollectionList 以根据 itemsPerRow 分组数据。groupedCollectionList() {const rows = [];for (let i = 0; i < this.list.length; i += this.itemsPerRow) {rows.push(this.list.slice(i, i + this.itemsPerRow));}return rows;},},beforeMount() {this.updateScreenSize(); //初始化屏幕宽度uni.onWindowResize(this.updateScreenSize);  // 监听屏幕尺寸变化},beforeDestroy() {uni.offWindowResize(this.updateScreenSize);  // 移除监听器},methods: {// 获取当前屏幕宽度getScreenWidth() {return uni.getSystemInfoSync().screenWidth;},updateScreenSize(){const width = this.getScreenWidth()console.log(width,'width');// 562<width&&width<687if (width > 640) {this.itemsPerRow = 3;} else if (562<width&&width < 640) {this.itemsPerRow = 2;} else {this.itemsPerRow = 1;}},getList() {// this.$modal.loading("加载中..");this.list = [{picture:"https://jis-eclass.oss-accelerate.aliyuncs.com/images/Course/20250108/20250108141759a888cbd5-8dec-4b98-a423-30d1f2081023.jpg",name:"测试1",createdTime:"2025-1-1"},{picture:"https://jis-eclass.oss-accelerate.aliyuncs.com/images/Course/20250108/20250108141759a888cbd5-8dec-4b98-a423-30d1f2081023.jpg",name:"测试2",createdTime:"2025-1-1"},{picture:"https://jis-eclass.oss-accelerate.aliyuncs.com/images/Course/20250108/20250108141759a888cbd5-8dec-4b98-a423-30d1f2081023.jpg",name:"测试3",createdTime:"2025-1-1"},{picture:"https://jis-eclass.oss-accelerate.aliyuncs.com/images/Course/20250108/20250108141759a888cbd5-8dec-4b98-a423-30d1f2081023.jpg",name:"测试4",createdTime:"2025-1-1"}]},},async onLoad(e) {const { id }  = ethis.id = id},onShow() {this.pageNum = 1;this.getList();},};
</script><style lang="scss" scoped>
.index {width: 100%;min-height: 100vh;background: #f7f8fc;box-sizing: border-box;padding-bottom: calc(110rpx + env(safe-area-inset-bottom));.activityList {width: 100%;padding: 0 20rpx;padding-top: 24rpx;.innerContent {width: 100%;background: #ffffff;border-radius: 20rpx;padding: 20rpx;.content-list {padding: 20rpx;padding-right: 0rpx;.list-row {display: flex;justify-content: space-between;margin-bottom: 20rpx;}.list-item {// 确保样式能够适应不同数量的每行显示。width: calc((100% - 40rpx * (itemsPerRow - 1)) / itemsPerRow);height: 152rpx;display: flex;margin-bottom: 20rpx;.item-left {width: 270rpx;height: 152rpx;border-radius: 10rpx;position: relative;.img {width: 270rpx;height: 152rpx;border-radius: 10rpx;}}.item-right {flex: 1;padding: 10rpx 0rpx;display: flex;flex-direction: column;justify-content: space-between;width: 200rpx;padding-left: 20rpx;.title {font-size: 30rpx;font-family: PingFang SC, PingFang SC-Regular;font-weight: Regular;text-align: left;color: #333333;line-height: 41rpx;}.title.space {white-space: nowrap;overflow: hidden;text-overflow: ellipsis;}}}}}}
}
</style>
http://www.mmbaike.com/news/32930.html

相关文章:

  • 经典企业网站欣赏网络舆情报告
  • 娄底做网站最近三天的新闻大事
  • 做平面哪个网站的素材最好上海比较好的seo公司
  • 山西省建设厅网站官网推广方案策划
  • 泉州学校网站开发包括哪些内容
  • 导航网站怎么赚钱营销团队找产品合作
  • wordpress 即时通讯关键词优化公司哪家效果好
  • wordpress文章列分页seo公司排名教程
  • 一级a做爰片免费网站体验区老鬼seo
  • b2c的网站seo排名优化教程
  • 免费聊天网站模板和源码百度推广代运营
  • 建设谷歌公司网站费用各大网站推广平台
  • 网站的外链建设计划qq推广官网
  • 武汉网址建站杭州seook优屏网络
  • 阿里云服务器发布网站北京seo学校
  • wordpress 网站播放器企业管理培训免费课程
  • 天河wap网站建设公司培训课程表
  • 网站开发vs2013网页设计需要学什么软件
  • wordpress拼音tag插件优化网络培训
  • 哪个网站做清洁的活多seo网络营销推广公司
  • 百度生成在线网站地图郑州怎么优化网站排名靠前
  • 界面设计与制作是做什么的广东seo外包服务
  • php网站开发就业前景个人网站规划书模板
  • 设计网站免费的培训班报名
  • 济南建站培训搜外网 seo教程
  • 东莞设计网站服务的公司网店代运营正规公司
  • 网站设计实例杭州seo薪资水平
  • 企业备案做电影网站的后果企业网站seo
  • 一级建造师招聘网最新招聘网站搜索优化公司
  • 免费发做网站seo标题优化