天天看點

微信小程式開發--建立歡迎頁面

本篇跟大家一起建立第一個頁面,歡迎頁面。

先看下最後的效果圖:

微信小程式開發--建立歡迎頁面

首先打開微信WEB開發者工具,建立quick start項目,簡單的修改一下。 目錄結構如下圖:

微信小程式開發--建立歡迎頁面
  • 把Index檔案夾重命名為welcome;
  • 底部的hello world改為一個類似于按鈕的樣式;
  • 添加背景顔色; 修改頂部樣式;

按鈕的實作:

下面是welcome頁面的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="btn">歡迎進入小程式開發</text>
  </view>
</view>
           

下面是welcome頁面的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;
}
 
.userinfo image{
  width: 200rpx;
  height: 200rpx;
  border-radius: 50%;
}
 
.usermotto {
  margin-top: 200px;
  border: 1px solid #405f80;
  width: 250rpx;
  height: 80rpx;
  text-align: center;
  border-radius: 5px;
}
.btn{
  font-size: 22rpx;
  font-family: MicroSoft Yahei;
  font-weight: bold;
  line-height: 80rpx;
}
page{
  height: 100%;
  background: #ECF8EB;
}
           

背景顔色的設定:

注意:在最外部的view設定寬高百分百,添加背景顔色是無效的。因為微信預設外面還有一層page。 

微信小程式開發--建立歡迎頁面

是以需要這樣寫:

page{
  height: 100%;
  background: #ECF8EB;
}
           

頂部設定:

app.jason代碼如下:

{
  "pages":[
    "pages/welcome/welcome"
     
  ],
  "window":{
    "backgroundTextStyle":"light",
    "navigationBarBackgroundColor": "#ECF8EB",
    "navigationBarTitleText": "歡迎",
    "navigationBarTextStyle":"black"
  }
}
           

本文涉及的源碼可以在這裡:http://bbs.html51.com/t-549-1-1/下載下傳。更多源碼和教程也可以通路51小程式去檢視。