微信小程序实现图片轮播及文件上传
刚刚接触微信小程序,看着网上的资源写了个小例子,本地图片轮播以及图片上传。
图片轮播:
index.js
<span style="font-size:14px;">var app = getApp() Page({ data:{ mode: 'aspectFit', // src:'../images/timg1.jpg', imgUrls:[ '../images/1.jpg', '../images/2.jpg', '../images/3.jpg', '../images/4.jpg' ], indicatorDots: true, //是否出现焦点 autoplay: true, //是否自动播放 interval: 2000, //自动播放时间间隔 duration: 1000, //滑动动画时间 userInfo: {} }, onLoad:function(){ console.log('onLoad Test'); } })</span>
注:imgUrls中为本地图片数组。
index.wxml:
<swiper indicator-dots = "{{indicatorDots}}" autoplay="{{autoplay}}" interval="{{interval}}" duration="{{duration}}"> <block wx:for="{{imgUrls}}"> <swiper-item class="swiper_i"> <image src="/UploadFiles/2021-04-02/{{item}}">index.json:
{ "navigationBarTitleText": "相册" }index.wxss:
.slide-image{ width:100%; height:100%; } .swiper_i{ text-align: center; width:100%; }好了,这是图片轮播的几个文件。会在app.json中配置。
接下来是图片上传的。因为没有服务器,暂时不能上传,但是可以从本地相册或拍照获取照片。
upload.js:
var app = getApp() Page({ data:{ // text:"这是一个页面" source: '', tt:false }, /** * 选择相册或者相机 配合上传图片接口用 */ onLoad: function() { var that = this; wx.chooseImage({ count: 1, //original原图,compressed压缩图 sizeType: ['original'], //album来源相册 camera相机 sourceType: ['album', 'camera'], //成功时会回调 success: function(res) { //重绘视图 that.setData({ source: res.tempFilePaths, tt:true }) /* var tempFilePaths = res.tempFilePaths wx.uploadFile({ url: 'https://', //仅为示例,非真实的接口地址 filePath: tempFilePaths[0], name: 'file', formData:{ 'user': 'test' }, success: function(res){ var data = res.data //do something } })*/ } }) }, /*onHide:function(){ this.setData({ source:'' }) }*/ })upload.json:
{ "navigationBarTitleText": "上传图片" }upload.wxml:
<view class="Container"> <image src="/UploadFiles/2021-04-02/{{source}}">upload.wxss:
/* pages/upload/upload.wxss */ .Container{ text-align:center; width:100%; } .image-i{ width:100%; height:100%; }app.js为空。
app.json:
{ "pages": [ "pages/index/index", "pages/upload/upload" ], "window": { "navigationBarTextStyle": "black", "navigationBarTitleText": "演示2", "navigationBarBackgroundColor": "#fbf9fe", "backgroundColor": "#fbf9fe" }, "networkTimeout": { "request": 10000, "connectSocket": 10000, "uploadFile": 10000, "downloadFile": 10000 }, "tabBar": { "list": [{ "pagePath": "pages/index/index", "text": "显示图片", "iconPath": "pages/images/icon_API.png", "selectedIconPath": "pages/images/icon_API_HL.png" },{ "pagePath": "pages/upload/upload", "text": "上传", "iconPath": "pages/images/icon_API.png", "selectedIconPath": "pages/images/icon_API_HL.png" }] }, "debug": true }感谢阅读,希望能帮助到大家,谢谢大家对本站的支持!
华山资源网 Design By www.eoogi.com
广告合作:本站广告合作请联系QQ:858582 申请时备注:广告合作(否则不回)
免责声明:本站资源来自互联网收集,仅供用于学习和交流,请遵循相关法律法规,本站一切资源不代表本站立场,如有侵权、后门、不妥请联系本站删除!
免责声明:本站资源来自互联网收集,仅供用于学习和交流,请遵循相关法律法规,本站一切资源不代表本站立场,如有侵权、后门、不妥请联系本站删除!
华山资源网 Design By www.eoogi.com
暂无评论...
更新日志
2024年09月20日
2024年09月20日
- 曾轶可.2011-一只猫的旅行【天娱传媒】【WAV+CUE】
- 黑神话悟空上品狼刺客精魄获取方法一览|上品狼刺客精魄收集攻略
- 视觉小说《神椿市建设中REGENERATE》将于2025年2月20日发售
- 黑神话悟空上品鼠弩手精魄获取方法一览|上品鼠弩手精魄收集攻略
- 中国音乐地图听见世界非物质文化遗产《非遗HQCD》wav
- 中国民乐合奏作品集《华夏之音HQ》头版限量编号[WAV+CUE]
- [电影原声带]黎允文《天将雄师》[FLAC+CUE]
- 曝NS继任机型已进入量产阶段:已花了30亿日元
- 不是Switch2?曝《马里奥惊奇》NS捆绑包即将公开
- 暖心任天堂!网友Switch维修返还时贴纸被完好保留
- 《国语老歌 经典对唱情歌 2CD》[WAV/分轨][1.1GB]
- 《刀郎 翻唱精选华语专辑 披着羊皮的狼 》[WAV+CUE][430MB]
- 《真的田震 中国乐坛红极一时的歌者 精品集》[WAV+CUE][300MB]
- 群星.1995-新滚石九大天王之情歌大全【滚石】【WAV+CUE】
- 群星.1993-滚石九大天王十二出好戏·纵夏欢唱【滚石】【WAV+CUE】