小程序模板传递信息

╰+攻爆jí腚メ 2023-01-12 14:57 225阅读 0赞
  1. <!-- 引入模板 -->
  2. <import src="../productList/productList.wxml"></import>
  3. <!-- 模板传递数据 -->
  4. <!-- <block wx:for="{ {listArr}}" wx:key="index" wx:for-item="obj"> <template is='productList' data="{ {obj}}"></template> </block> -->
  5. <!--或者 <template is='productList' data="{ {item}}"></template> 不需要加 wx:for-item="obj" -->
  6. <!-- 展开对象 ...item 展开运算符 item={id:'',title:'',} 获取item.id item.title ...item=id:'',title:'' 获取 :id,title -->
  7. <block wx:for="{ {listArr}}" wx:key="index" >
  8. <template is='productList' data='{ {...item}}'></template>
  9. </block>

js:

  1. data: {
  2. listArr:[{
  3. id:1,
  4. imgUrl:'',
  5. title:'产品信息1'
  6. },
  7. {
  8. id:2,
  9. imgUrl:'',
  10. title:'产品信息2'
  11. },
  12. {
  13. id:3,
  14. imgUrl:'',
  15. title:'产品信息3'
  16. },
  17. {
  18. id:4,
  19. imgUrl:'',
  20. title:'产品信息4'
  21. },
  22. {
  23. id:5,
  24. imgUrl:'',
  25. title:'产品信息5'
  26. },
  27. {
  28. id:6,
  29. imgUrl:'',
  30. title:'产品信息6'
  31. },
  32. {
  33. id:7,
  34. imgUrl:'',
  35. title:'产品信息7'
  36. },
  37. {
  38. id:8,
  39. imgUrl:'',
  40. title:'产品信息8'
  41. },
  42. {
  43. id:9,
  44. imgUrl:'',
  45. title:'产品信息9'
  46. },
  47. {
  48. id:10,
  49. imgUrl:'',
  50. title:'产品信息10'
  51. },
  52. {
  53. id:11,
  54. imgUrl:'',
  55. title:'产品信息11'
  56. },
  57. {
  58. id:12,
  59. imgUrl:'',
  60. title:'产品信息12'
  61. },
  62. {
  63. id:13,
  64. imgUrl:'',
  65. title:'产品信息13'
  66. },
  67. {
  68. id:14,
  69. imgUrl:'',
  70. title:'产品信息14'
  71. },
  72. {
  73. id:15,
  74. imgUrl:'',
  75. title:'产品信息15'
  76. }]
  77. },

引入的页面:

  1. <!--pages/productList/productList.wxml-->
  2. <text>pages/productList/productList.wxml</text>
  3. <!-- <template name="productList"> <view class="list"> <view class="img">图片{ {obj.id}}</view> <view class="text">{ {obj.title}}</view> </view> </template> -->
  4. <template name="productList">
  5. <view class="list">
  6. <view class="img">图片{
  7. {id}}</view>
  8. <view class="text">{
  9. {title}}</view>
  10. </view>
  11. </template>

css:

  1. /* pages/productList/productList.wxss */
  2. .list{
  3. display: flex;
  4. padding-bottom: 10rpx;
  5. border-bottom: 1rpx solid #eee;
  6. margin-top: 20rpx;
  7. }
  8. .img{
  9. width: 240rpx;
  10. height: 240rpx;
  11. background: pink;
  12. }
  13. .text{
  14. flex: 1;
  15. padding-left: 30rpx;
  16. }

效果展示:
在这里插入图片描述

发表评论

表情:
评论列表 (有 0 条评论,225人围观)

还没有评论,来说两句吧...

相关阅读

    相关 程序 程序列表模板

    小程序列表模板 今天做小程序列表页面 百度搜了一圈也没有一个模板 今天花了两个小时自己做了一个 放图 ! 中间的隔离线在手机显示的时候颜色比较浅 截图上面显示的比较深

    相关 程序传递对象数组

    其他数据格式暂时不知道,我的数据主要是对象数组格式,传递的时候总是获取不到数据。所以网上找了好多没有具体方案。自己写了一下。仅供参考! arraylist2 是一个数组,数据