微信小程序 案例 学习 1
2017-01-04 16:59
417 查看
//index.js //获取应用实例 var app = getApp() Page({ data: { welcome: '欢迎来到微信小程序', userimage:'获取域名', chouseImages:'上传图片', userInfo: {}, tempFilePaths:'' }, //事件处理函数 bindViewTap: function() { wx.navigateTo({ url: '../logs/logs' }) }, bindUserImage:function(){ wx.navigateTo({ url:'../users/images' }) }, chooseimage:function(){ var _this = this wx.chooseImage({ count: 1, sizeType: ['original', 'compressed'], sourceType: ['album', 'camera'], success: function (res) { _this.setData({ tempFilePaths:res.tempFilePaths }) } }) }, onLoad: function () { console.log('onLoad') var that = this //调用应用实例的方法获取全局数据 app.getUserInfo(function(userInfo){ //更新数据 that.setData({ userInfo:userInfo }) console.log(userInfo); }) } }) index.wxml <!--index.wxml--> <view class="container"> <view bindtap="bindViewTap" class="userinfo"> <image class="userinfo-avatar" src="{{userInfo.avatarUrl}}" background-size="cover"></image> <text class="userinfo-nickname">{{userInfo.nickName}}</text> </view> <view class="usermotto"> <text class="user-motto">{{welcome}}</text> </view> <view bindtap="bindUserImage" class="userimage"> <text class="user-image">{{userimage}}</text> </view> <button class="userimage" bindtap="chooseimage">{{chouseImages}}</button> <image src="{{tempFilePaths}}" /> </view> /**index.wxss**/ .userinfo { display: flex; flex-direction: column; align-items: center; } .userinfo-avatar { width: 128rpx; height: 128rpx; margin: 20rpx; border-radius: 50%; } .userinfo-nickname { color: #aaa; } .usermotto { margin-top: 100px; } .userimage{ margin-top: 20px; color: #aaa; } .userimage img{ width: 10px; height: 10px; }
相关文章推荐
- 微信开发学习日记(二):3个案例
- 微信开发学习日记(二):3个案例
- 微信:小程序学习笔记(2)
- 微信小程序学习笔记(2)----HelloWorld分析
- 微信小程序学习笔记(1)----学习资料整理
- 重构遗留程序的一次案例学习(java程序)
- 微信小程序之组件学习2
- 微信小程序示视频应用场景例利用腾讯云仅限开发案例四
- Android(java)学习笔记85:案例拨号程序
- {HTML5学习图谱}随着微信小程序的出现,HTML5将会炙手可热!
- 微信小程序--text组件学习
- 神技!微信小程序(应用号)抢先入门体验(附最新案例-豆瓣电影)持续更新
- 微信小程序示相册例利用腾讯云仅限开发案例一
- 微信开发学习日记(二):3个案例
- 微信:小程序学习笔记(1)
- 神技!微信小程序(应用号)抢先入门教程(附最新案例DEMO-豆瓣电影)持续更新
- 学习微信小程序-索引贴
- 微信小程序之组件学习