查看“结合回调函数操作API”的源代码
←
结合回调函数操作API
跳转至:
导航
,
搜索
因为以下原因,您没有权限编辑本页:
您所请求的操作仅限于该用户组的用户使用:
用户
您可以查看与复制此页面的源代码。
<div style="width:20px;height:20px;background-image: linear-gradient(120deg, #e0c3fc 0%, #8ec5fc 100%);border-radius:50%;display:inline-block;"></div> <p style="display:inline-block;font-weight: bold;font-size:1.8em">例一:</p> 我们先来看媒体中的获取图片信息的函数: <span style="background:#f9f2f4;color:#c7254e">wx.getImageInfo(对象对象)</span> 该函数的作用是获取图片信息。网络图片需要先配置下载域名才能实现。 函数参数: [[文件:图片1.png]] object.success附加函数参数: [[文件:图片2.png]] res.orientation的合法值: [[文件:图片3.png]] 代码示例: <p style="color:#999">//index.js</p> const app=getApp() Page({ data:{ src:'../../imgs/pic.jpg' }, getImgInfo:function(){ wx.getImageInfo({ src:this.data.src, success(res) { //回调函数 console.log(res) }, fail(res){ console.log(res) }, complete(res){ console.log('一定会执行') } }) } }) <p style="color:#999">//index.wxml</p> <nowiki><view>下面是一个获取图片信息的按钮</view></nowiki> <nowiki><button bindtap='getImgInfo'>点一下</button></nowiki> 运行 输出图片信息: [[文件:图片4.png]] <div style="width:20px;height:20px;background-image: linear-gradient(120deg, #e0c3fc 0%, #8ec5fc 100%);border-radius:50%;display:inline-block"></div> <p style="display:inline-block;font-weight: bold;font-size:1.8em">例二:</p> 再来看一下界面相互作用中的 <span style="background:#f9f2f4;color:#c7254e">wx.showToast</span> 函数 该函数的作用是显示消息提示框 函数参数: [[文件:图片5.png]] 代码示例: <p style="color:#999">//index.js</p> const app = getApp() Page({ data: { src:'../../imgs/pic.jpg' }, //事件触发函数 showImgInfo:function(text){ wx.showToast({ title: text, icon:'none' }) }, getImgInfo:function(){ var that=this wx.getImageInfo({ src: this.data.src, success(res) { // 回调函数 委托 执行者变化 that.showImgInfo('路径->'+res.path+'\n尺寸'+res.width+'X'+res.height) }, fail(res){ console.log(res) }, complete(res){ console.log('一定会执行',res) } }) } }) 运行,获得图片信息,并在交互界面上看到所输出的图片信息
返回至
结合回调函数操作API
。
导航菜单
个人工具
登录
命名空间
页面
讨论
变种
视图
阅读
查看源代码
查看历史
更多
搜索
导航
首页
最近更改
随机页面
帮助
工具
链入页面
相关更改
特殊页面
页面信息