收藏
回答

程序不报错但是图片出不来

框架类型 问题类型 操作系统 工具版本
小程序 Bug Windows 542

绝对是bug

<view class="container">

 <scroll-view scroll-y="true" scroll-into-view="{{scrollIntoView}}" bindscroll="onScroll">

   <swiper indicator-dots="{{indicatorDots}}" autoplay="{{autoplay}}" interval="{{interval}}" duration="{{duration}}">

     <block wx:for="{{imgUrls}}">

       <swiper-item>

         <image src="{{item}}" class="slide-image" width="355" height="150" />

       </swiper-item>

     </block>

   </swiper>

   <swiper indicator-dots="{{indicatorDots}}" autoplay="{{autoPlay}}">

     <swiper-item wx:for="{{icons}}" wx:for-item="list" wx:key="id">

        <view class="icon" wx:for="{{list}}" wx:for-item="icon" wx:key="id" bindtap="toNearby">

          <image src="{{icon.img}}"/>

          <text>{{icon.name}}</text>

        </view>

      </swiper-item>

   </swiper>

 </scroll-view>

</view>



var qcloud = require('../../vendor/wafer2-client-sdk/index')

var config = require('../../config')

var util = require('../../utils/util.js')


Page({

 data: {

   imgUrls: [

     '../../imgs/index/404625.jpg',

     '../../imgs/index/404625.jpg',

     '../../imgs/index/404625.jpg'

   ],

   indicatorDots: true,

   autoplay: true,

   interval: 5000,

   duration: 1000,

   autoPlay: false,

   icons: [

     [

       {

         id: 1,

         img: '../../imgs/index/icon_1.jpg',

         name: '美食',

         url: ''

       },

       {

         id: 2,

         img: '../../imgs/index/icon_2.jpg',

         name: '超市',

         url: ''

       },

       {

         id: 3,

         img: '../../imgs/index/icon_3.jpg',

         name: '鲜果购',

         url: ''

       },

       {

         id: 4,

         img: '../../imgs/index/icon_4.jpg',

         name: '下午茶',

         url: ''

       },

       {

         id: 5,

         img: '../../imgs/index/icon_5.jpg',

         name: '正餐优选',

         url: ''

       },

       {

         id: 6,

         img: '/imgs/index/icon_6.jpg',

         name: '外卖专送',

         url: ''

       },

       {

         id: 7,

         img: '/imgs/index/icon_7.jpg',

         name: '饮品站',

         url: ''

       },

       {

         id: 8,

         img: '/imgs/index/icon_8.jpg',

         name: '小吃馆',

         url: ''

       }

     ],

     [

       {

         id: 9,

         img: '/imgs/index/icon_9.jpg',

         name: '新商家',

         url: ''

       },

       {

         id: 10,

         img: '/imgs/index/icon_10.jpg',

         name: '免配送费',

         url: ''

       },

       {

         id: 11,

         img: '/imgs/index/icon_11.jpg',

         name: '鲜花蛋糕',

         url: ''

       },

       {

         id: 12,

         img: '/imgs/index/icon_12.jpg',

         name: '名气餐厅',

         url: ''

       },

       {

         id: 13,

         img: '/imgs/index/icon_13.jpg',

         name: '异国料理',

         url: ''

       },

       {

         id: 14,

         img: '/imgs/index/icon_14.jpg',

         name: '家常菜',

         url: ''

       },

       {

         id: 15,

         img: '/imgs/index/icon_15.jpg',

         name: '能量西餐',

         url: ''

       },

       {

         id: 16,

         img: '/imgs/index/icon_16.jpg',

         name: '无辣不欢',

         url: ''

       }

     ]

   ]

 },


 // 用户登录示例

 login: function () {

   if (this.data.logged) return


   util.showBusy('正在登录')

   var that = this


   // 调用登录接口

   qcloud.login({

     success(result) {

       if (result) {

         util.showSuccess('登录成功')

         that.setData({

           userInfo: result,

           logged: true

         })

       } else {

         // 如果不是首次登录,不会返回用户信息,请求用户信息接口获取

         qcloud.request({

           url: config.service.requestUrl,

           login: true,

           success(result) {

             util.showSuccess('登录成功')

             that.setData({

               userInfo: result.data.data,

               logged: true

             })

           },


           fail(error) {

             util.showModel('请求失败', error)

             console.log('request fail', error)

           }

         })

       }

     },


     fail(error) {

       util.showModel('登录失败', error)

       console.log('登录失败', error)

     }

   })

 },


 // 切换是否带有登录态

 switchRequestMode: function (e) {

   this.setData({

     takeSession: e.detail.value

   })

   this.doRequest()

 },


 doRequest: function () {

   util.showBusy('请求中...')

   var that = this

   var options = {

     url: config.service.requestUrl,

     login: true,

     success(result) {

       util.showSuccess('请求成功完成')

       console.log('request success', result)

       that.setData({

         requestResult: JSON.stringify(result.data)

       })

     },

     fail(error) {

       util.showModel('请求失败', error);

       console.log('request fail', error);

     }

   }

   if (this.data.takeSession) {  // 使用 qcloud.request 带登录态登录

     qcloud.request(options)

   } else {    // 使用 wx.request 则不带登录态

     wx.request(options)

   }

 },


 // 上传图片接口

 doUpload: function () {

   var that = this


   // 选择图片

   wx.chooseImage({

     count: 1,

     sizeType: ['compressed'],

     sourceType: ['album', 'camera'],

     success: function (res) {

       util.showBusy('正在上传')

       var filePath = res.tempFilePaths[0]


       // 上传图片

       wx.uploadFile({

         url: config.service.uploadUrl,

         filePath: filePath,

         name: 'file',


         success: function (res) {

           util.showSuccess('上传图片成功')

           console.log(res)

           res = JSON.parse(res.data)

           console.log(res)

           that.setData({

             imgUrl: res.data.imgUrl

           })

         },


         fail: function (e) {

           util.showModel('上传图片失败')

         }

       })


     },

     fail: function (e) {

       console.error(e)

     }

   })

 },


 // 预览图片

 previewImg: function () {

   wx.previewImage({

     current: this.data.imgUrl,

     urls: [this.data.imgUrl]

   })

 },


 // 切换信道的按钮

 switchChange: function (e) {

   var checked = e.detail.value


   if (checked) {

     this.openTunnel()

   } else {

     this.closeTunnel()

   }

 },


 openTunnel: function () {

   util.showBusy('信道连接中...')

   // 创建信道,需要给定后台服务地址

   var tunnel = this.tunnel = new qcloud.Tunnel(config.service.tunnelUrl)


   // 监听信道内置消息,包括 connect/close/reconnecting/reconnect/error

   tunnel.on('connect', () => {

     util.showSuccess('信道已连接')

     console.log('WebSocket 信道已连接')

     this.setData({ tunnelStatus: 'connected' })

   })


   tunnel.on('close', () => {

     util.showSuccess('信道已断开')

     console.log('WebSocket 信道已断开')

     this.setData({ tunnelStatus: 'closed' })

   })


   tunnel.on('reconnecting', () => {

     console.log('WebSocket 信道正在重连...')

     util.showBusy('正在重连')

   })


   tunnel.on('reconnect', () => {

     console.log('WebSocket 信道重连成功')

     util.showSuccess('重连成功')

   })


   tunnel.on('error', error => {

     util.showModel('信道发生错误', error)

     console.error('信道发生错误:', error)

   })


   // 监听自定义消息(服务器进行推送)

   tunnel.on('speak', speak => {

     util.showModel('信道消息', speak)

     console.log('收到说话消息:', speak)

   })


   // 打开信道

   tunnel.open()


   this.setData({ tunnelStatus: 'connecting' })

 },


 /**

  * 点击「发送消息」按钮,测试使用信道发送消息

  */

 sendMessage() {

   if (!this.data.tunnelStatus || !this.data.tunnelStatus === 'connected') return

   // 使用 tunnel.isActive() 来检测当前信道是否处于可用状态

   if (this.tunnel && this.tunnel.isActive()) {

     // 使用信道给服务器推送「speak」消息

     this.tunnel.emit('speak', {

       'word': 'I say something at ' + new Date(),

     });

   }

 },


 /**

  * 点击「关闭信道」按钮,关闭已经打开的信道

  */

 closeTunnel() {

   if (this.tunnel) {

     this.tunnel.close();

   }

   util.showBusy('信道连接中...')

   this.setData({ tunnelStatus: 'closed' })

 }

})



回答关注问题邀请回答
收藏

1 个回答

  • HS
    HS
    2018-05-19

    在图片加个 binderror 打印一下错误呢

    2018-05-19
    有用
    回复 7
    • lhy
      lhy
      2018-06-29

      你好,我用wx.chooseImage突然报错了,开始都好好的,突然报错,然后在success回调里面的方法的代码都不执行了,我把success里面的代码注释完了还是报这个错


      2018-06-29
      回复
    • HS
      HS
      2018-06-29回复lhy

      从这个错误信息 index.js:387 点进去断点看看报错详细信息呢

      2018-06-29
      回复
    • lhy
      lhy
      2018-06-29回复HS

      我看了一下报错的位置,是jssdk文件中的这里在报错

      2018-06-29
      回复
    • lhy
      lhy
      2018-06-29回复HS


      2018-06-29
      回复
    • HS
      HS
      2018-06-29回复lhy

      工具的版本是多少呢

      2018-06-29
      回复
    查看更多(2)
登录 后发表内容