javascript - 微信小程序如何通过带参数的url调用方法处理数据?url写在app.json里吗?对应的方法写在哪里?
PHP中文网
PHP中文网 2017-04-11 12:28:55
0
1
379

刚学微信小程序,前端勉强写了点,但是到了处理数据的就不太懂了,之前写springMVC,js学的很差,看不懂小程序怎么调用方法的, app.json 的pages 里面写了跳转的URL, 处理数据的url也是写在这里的吗?? 带参数的怎么写?有没有例子, 还有方法就用JS写在page 页面的 .js文件里吗???
下面是代码,我要做一个 图片长按 跳出保存的sheet,点击保存就下载到手机里, 调用wx.downfile,但看文档好像还要调用wx.savefile,真的不太懂,请高手解释一些
wx.saveFile({
success: function(res) {

var tempFilePath = res.tempFilePath
wx.saveFile({
  tempFilePath: tempFilePath,
  success: function(res) {
    var savedFilePath = res.savedFilePath
  }
})

}
})

<image class="image"data-id="1" bindlongtap="longtap11" bindtouchend="touchend" style="width:{{width}}rpx;height:{{height}}rpx"
src="图片的网络地址" mode="aspectFit"></image>
  longtap11:function(e){
    wx.showActionSheet({
      itemList: ['保存图片'],
      success: function(res) {
        console.log(res.tapIndex);
        var picid=e.target.dataset.id;
        wx.downloadFile({
        url: 'http://download/pic?id='+ picid, //这个url是用来做什么的? 调用方法写在哪里?如何映射到那个方法?
          success: function(res) {
            wx.playVoice({
              filePath: res.tempFilePath
            })
          }
        })
      },
      fail: function(res) {
        console.log(res.errMsg)
      }
    })
  },
PHP中文网
PHP中文网

认证高级PHP讲师

Antworte allen(1)
黄舟

有点乱,我回答我看明白的问题。

1、app.json 是一个配置文件,只负责小程序的全局配置。
2、带参数URL跳转就像这样 page/index?id=1&from=web,这样目录页面 page/index 页面的 onLoad(options) {},其中 options 存储着 { id: 1, from: 'web' }
3、wx.downloadFile 用来下载远程资源,而 wx.saveFile 是保存一个文件。这二者的区别是前者是把文件下载到临时区,后者是将临时区的文件保存到用户指定的位置上。

以上。

Beliebte Tutorials
Mehr>
Neueste Downloads
Mehr>
Web-Effekte
Quellcode der Website
Website-Materialien
Frontend-Vorlage
Über uns Haftungsausschluss Sitemap
Chinesische PHP-Website:Online-PHP-Schulung für das Gemeinwohl,Helfen Sie PHP-Lernenden, sich schnell weiterzuentwickeln!