微信小程序选择图片代码哪里错误了?
看下代码,哪里错啦?
//index.js
//获取应用实例
var app = getApp()
Page({
data: {
motto: '查看操作日志',
userImgUrl:null,
userInfo: {}
},
//事件处理函数
bindViewTap: function() {
wx.navigateTo({
url: '../logs/logs'
})
},
setHeaderImg:function(){
var page = this;
wx.chooseImage({
count: 1, // 默认9
sizeType: ['original', 'compressed'], // 可以指定是原图还是压缩图,默认二者都有
sourceType: ['album', 'camera'], // 可以指定来源是相册还是相机,默认二者都有
success: function (res) {
// 返回选定照片的本地文件路径列表,tempFilePath可以作为img标签的src属性显示图片
var tempFilePaths = res.tempFilePaths;
console.log(tempFilePaths);
page.setData({userImgUrl:tempFilePaths})
}
})
},
onLoad: function () {
console.log('onLoad')
var that = this
//调用应用实例的方法获取全局数据
app.getUserInfo(function(userInfo){
//更新数据
that.setData({
userInfo:userInfo
})
})
}
})
<!--index.wxml-->
<view class="container">
<view bindtap="bindViewTap" class="userinfo">
<image wx:if="{{userImgUrl!=null}}" class="userinfo-avatar" src="{{userImgUrl}}" background-size="cover"></image>
<image wx:else class="userinfo-avatar" src="{{userInfo.avatarUrl}}" background-size="cover"></image>
<text class="userinfo-nickname">{{userInfo.nickName}}</text>
</view>
<view bindtap="bindViewTap" class="usermotto">
<text class="user-motto">{{motto}}</text>
</view>
<view class="user-welcome">
<text class="user-motto">欢迎您,{{userInfo.nickName}}</text>
<!--添加一个修改头像的按钮-->
<button type="primary" size="{{default}}" loading="{{false}}" plain="{{false}}"
disabled="{{false}}" bindtap="setHeaderImg"> 更改头像 </button>
</view>
</view>