自定义组件
自定义组件包含image标签,在page使用setData设置图片路径(网络图片)传给组件没法显示图片。问题版本: ios 6.5.14
若是使用page里的data的常量logo: "https://…jpg"能够成功显示。
自定义组件包含image标签,在page使用setData设置图片路径(网络图片)传给组件没法显示图片。问题版本: ios 6.5.14
若是使用page里的data的常量logo: "https://…jpg"能够成功显示。
1.组件image-text-vertical.wxml
<!-- 纵向图文组件--> < view class = "image-text-vertical" bind:tap = "selected" > < image class = "icon" src = "{{imagePath}}" lazy-load = "{{true}}" ></ image > < text class = "title" >{{title}} </ text > </ view > |
2.组件image-text-vertical.js
Component({ properties: { title: { type: String }, imagePath: { type: String }, data: { type: Object } }, methods: { selected: function () { this .triggerEvent( 'selected' , this .data) } } }) |
3.组件image-text-vertical.json
{ "component" : true } |
4.组件image-text-vertical.wxss
. icon { width : 40px ; height : 40px ; display : block ; margin : 10px auto 5px ; text-align : center ; } .title { height : 30px ; line-height : 30px ; display : block ; text-align : center ; } .image-text-vertical { color : #000 ; width : 25% ; size : 14px ; float : left ; } |
5.页面page.wxml
< view > < image-text-vertical wx:for = "{{hotBrands}}" wx:for-item = "hotBrand" wx:key = "hotBrand.id" data = "{{hotBrand}}" title = "{{hotBrand.name}}" imagePath = "{{ hotBrand.logo }}" > </ image-text-vertical > </ view > |
6.页面page.js
Page({ /** * 页面的初始数据 */ data: { hotBrands: [] }, onShow: function () { this .initData(); }, initData() { var hotBrands = [{id: "1" , name: "test1" , logo: "https://standby.cheshijian.net/zx_cb_web/userfiles/image201708/17/UPpYLVvyatRfM3hraNg7Ay.jpg" }, {id: "2" , name: "test2" , logo: "https://standby.cheshijian.net/zx_cb_web/userfiles/image201708/17/UPpYLVvyatRfM3hraNg7Ay.jpg" }, {id: "3" , name: "test3" , logo: "https://standby.cheshijian.net/zx_cb_web/userfiles/image201708/17/UPpYLVvyatRfM3hraNg7Ay.jpg" }, {id: "4" , name: "test4" , logo: "https://standby.cheshijian.net/zx_cb_web/userfiles/image201708/17/UPpYLVvyatRfM3hraNg7Ay.jpg" }, {id: "5" , name: "test5" , logo: "https://standby.cheshijian.net/zx_cb_web/userfiles/image201708/17/UPpYLVvyatRfM3hraNg7Ay.jpg" }, {id: "6" , name: "test6" , logo: "https://standby.cheshijian.net/zx_cb_web/userfiles/image201708/17/UPpYLVvyatRfM3hraNg7Ay.jpg" }, {id: "7" , name: "test7" , logo: "https://standby.cheshijian.net/zx_cb_web/userfiles/image201708/17/UPpYLVvyatRfM3hraNg7Ay.jpg" }, {id: "8" , name: "test8" , logo: "https://standby.cheshijian.net/zx_cb_web/userfiles/image201708/17/UPpYLVvyatRfM3hraNg7Ay.jpg" }]; this .setData({ hotBrands: hotBrands }); } }) |
7.页面page.json
{ "usingComponents" : { "image-text-vertical" : "../components/image-text-vertical/image-text-vertical" } } |
WXOPEN Club 社区为国内最专业的微信小程序技术社区,致力于微信小程序的技术研究。
社区由 Nodeclub 驱动 | 服务器搭建在超友好的 | 存储赞助商为 | 站点运行状态监控由 强力驱动
© 2016 - 2024 WXOPEN Club