本篇跟大家一起創建第一個頁面,歡迎頁面。
先看下最后的效果圖:

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

<!--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小程序去查看。
新聞熱點
疑難解答