获取用户信息
第一种官方不推荐
<view>当前用户名:{{name}}</view>
<view>获取用户头像
<image src="{{path}}" style="height:200rpx;width:200rpx"></image>
</view>
<view bindtap="getUsrName">获取房前用户名:</view>
data: {
message:"大白菜",
name:'',
path:'/img/mryhtx.png'
},
changData:function(){
console.log(this.data.message);
this.setData({message:"大沙雕大白菜"})
},
getUsrName:function(){
var that = this;
console.log('sdf');
wx.getUserInfo({
success: function(res) {
console.log('success',res)
that.setData({
name:res.userInfo.nickName,
path:res.userInfo.avatarUrl
})
},
file:function(res){
}
})
}
第二种官方推荐的方法
<button open-type="getUserInfo" bindgetuserinfo="xxxx" >获取用户信息 </button>
xxxx:function(){
wx.getUserInfo({
success: function(res) {
console.log('success',res)
},
file:function(res){
}
})
wx.openSetting(){}
获取用户位置
<view bindtap="getLocalPath">{{localPath}}</view>
Page({
data: {
localPath:"当前位置信息"
},
getLocalPath:function(){
var that=this;
wx.chooseLocation({
success:function(res){
that.setData({localPath:res.address});
},
})
}
})
for指令
//<text>商品列表展示:</text>
//<view>
//<view wx:for="{{dataList}}">{{index}}-{{item}}</view>
//</view>
<text>商品列表展示:</text>
<view>
<view wx:for="{{dataList}}" wx:for-index="idx" wx:for-item="x">{{idx}}-{{x}}</view>
</view>
<view>
{{userInfo.name}}
{{userInfo.age}}
</view>
<view>
<view wx:for="{{userInfo}}">{{index}}-{{item}}</view>
</view>
Page({
data: {
dataList:[],
userInfo:{
name:'',
age:
}
}
})
获取图片
<text>pages/publish/publish.wxml</text>
<view bindtap="uploadImage">请上传图片</view>
<view class="container">
<image wx:for="{{imageList}}" src="{{item}}"> </image>
</view>
Page({
data: {
imageList:[]
},
uploadImage:function(){
var that=this;
wx.chooseImage({
count: 9,
siceType:,
sourceType :,
success:function(res){
that.setData({
imageList:that.data.imageList.concat(res.tempFilePaths)
});
}
});
}
})
.container image{
width: 200rpx;
height:200rpx;
padding:5rpx;
}