WeChat アプレット開発実践の現地生活
準備の基礎知識
- アプレット開発ツールをダウンロードして、簡単なアプレットを作成します
- 基本的なアプレット コンポーネントの使用、API の理解
- js、css、html構文の理解
2. レベル別の効果実感手順
効果:
ステップ:
- 1.配置app.json中导航栏、tabBar效果
- 2.配置导航栏
- 3.实现轮播图
- 4.实现九宫格
- 5.实现图片布局
3ページ追加
- app.jsonのインデックスを削除する
- app.json に 3 ページを追加します。
- ナビゲーションバーを変更する
"pages": [
"pages/home/home",
"pages/message/message",
"pages/contact/contact"
],
"window": {
"backgroundTextStyle": "dark",
"navigationBarBackgroundColor": "#27BB9A",
"navigationBarTitleText": "本地生活",
"navigationBarTextStyle": "white",
"enablePullDownRefresh": true
},
tabBar 効果を構成する
app.jsonにtabBarを追加
アイコンを画像フォルダーに入れます
"tabBar": {
"list": [{
"pagePath": "pages/home/home",
"text": "首页",
"iconPath": "./images/home.png",
"selectedIconPath": "./images/home-active.png"
},{
"pagePath": "pages/message/message",
"text": "消息",
"iconPath": "./images/message.png",
"selectedIconPath": "./images/message-active.png"
},{
"pagePath": "pages/contact/contact",
"text": "联系我们",
"iconPath": "./images/contact.png",
"selectedIconPath": "./images/contact-active.png"
}]
}
カルーセルの実現
Pages/home/home.xml はコンポーネントに基づいてピクチャ フレームを構築します
<!--轮播图区域-->
<!--indicator-dots 属性:显示面板指示点-->
<swiper indicator-dots circular>
<!--第一页-->
<swiper-item wx:for="{
{swiperList}}" wx:key="id">
<image src="{
{item.image}}"></image>
</swiper-item>
</swiper>
Pages/home/home.wxss デザイン カルーセル スタイル
/* pages/home/home.wxss */
swiper {
height: 350rpx;
}
swiper image {
width: 100%;
height: 100%;
}
Pages/home/home.js リクエストを通じてカルーセル画像を取得します
手順: 1. データでカルーセルを受け取る配列を追加します: swiperList: [],
2.取得関数getSwiperList()を追加
3. onLoad: function (options) に関数を登録して、ページに入ったときにそのうちの 1 つが開始されるようにします: this.getSwiperList()
data: {
//存放轮播图的数据列表
swiperList: [],
},
onLoad: function (options) {
this.getSwiperList()
this.getGridList()
},
//获取轮播图数据的方法
getSwiperList() {
wx.request({
url: 'https://www.escook.cn/slides',
method:'GET',
success:(res) => {
this.setData({
swiperList:res.data
})
}
})
},
九公歌アイコンの実現
Pages/home/home.xml はコンポーネントに基づいてピクチャ フレームを構築します
<!--九宫格区域-->
<view class="grid-list">
<view class="grid-item" wx:for="{
{gridList}}" wx:key="id">
<image src="{
{item.icon}}"></image>
<text>{
{item.name}}</text>
</view>
</view>
Pages/home/home.wxss九公歌スタイルのデザインの難しさ
/*外围大box*/
.grid-list{
display:flex;
flex:wrap /*多行且换行显示*/
border-left: 1rpx solid #efefef;
border-top: 1rpx solid #efefef;
}
/*每个图文*/
.grid-item{
display:flex
flex-direction:column;/*文字和图片按照列的方向排放*/
align-item: center;/*纵向居中*/
justify-content: center;/*横向居中居中*/
border-right: 1rpx solid #efefef;/*边框理解*/
border-bottom: 1rpx solid #efefef;
box-sizing: border-box;;/*默认是content-box百度自行理解*/
}
/*设置图片和文字的大小*/
.grid-item image {
width: 60rpx;
height: 60rpx;
}
.grid-item text {
font-size: 24rpx;
margin-top: 10rpx;
}
Pages/home/home.jsに設定されている画像の取得は上記カルーセル画像と同様です
data: {
//存放轮播图的数据列表
swiperList: [],
//存放九宫格数据列表
gridList: []
},
/**
* 生命周期函数--监听页面加载
*/
onLoad: function (options) {
this.getSwiperList()
this.getGridList()
},
//获取轮播图数据的方法
getSwiperList() {
wx.request({
url: 'https://www.escook.cn/slides',
method:'GET',
success:(res) => {
this.setData({
swiperList:res.data
})
}
})
},
// 获取九宫格数据的方法
getGridList() {
wx.request({
url: 'https://www.escook.cn/categories',
method: 'GET',
success: (res) => {
this.setData({
gridList: res.data
})
}
})
},
終了画面設定(簡易)
Pages/home/home.xml はコンポーネントに基づいてピクチャ フレームを構築します
<!--图片区域-->
<view class="img-box">
<image src="../../images/link-01.png"></image>
<image src="../../images/link-02.png"></image>
</view>
Pages/home/home.wxss デザイン画像スタイル
.img-box{
display:flex;
justify-content:space-around;
padding: 20rpx 10rpx;/* 上边下边 | 左边右边 */
}
.img-box image {
width: 45%;
}