微信小程序全方位深度解析课程Dome-First项目index

微信小程序全方位深度解析课程Dome-First项目index
课程观看地址:http://edu.csdn.net/course/detail/3081

//index.js
//获取应用实例
var app = getApp()
//相对路径
var common = require("../../common/common");
Page({
  data: {
    motto: 'tangcaiye',
    userInfo: {}
  },
  //事件处理函数
  bindViewTap: function() {
    console.log(this.data.motto);
    //页面跳转
    wx.navigateTo({
      url: '../logs/logs'
    })
  },
  changeMotto:function (){

    this.setData({
      motto:"你好 世界!"
    });
  },
  //当页面加载好之后执行的
  onLoad: function () {
    common.sayHello("zhagnsan");
    console.log('onLoad')
    var that = this
    //调用应用实例的方法获取全局数据
    app.getUserInfo(function(userInfo){
      //更新数据
      console.log(userInfo);
      that.setData({
        userInfo:userInfo
      })
    })
  }
})



//index.json
{
    "navigationBarTitleText": "首页"
}


<!--index.wxml-->
<view class="container">
  <view  bindtap="bindViewTap" class="userinfo">
    <image class="userinfo-avatar" src="{{userInfo.avatarUrl}}"></image>
    <text class="userinfo-nickname">主讲人:{{userInfo.nickName}}</text>
  </view>
  <view class="usermotto">
    <text class="user-motto">内容:{{motto}}</text>
  </view>
</view>

/**index.wxss**/
.userinfo {
  
  flex-direction: column;
  align-items: center;
  text-align: center;
}

.userinfo-avatar {
  width: 100px;
  height: 100px;
  margin: 20px;
  border-radius: 50%;
}

.userinfo-nickname {
  color: green;
  font-size: 30px;
  display: block;
}

.usermotto {
  margin-top: 20px;
}




相关内容推荐