一起開發微信小程序
發表時(shí)間:2021-4-30
發布人(rén):融晨科技
浏覽次數:92
每個(gè)小程序包含三個(gè)必不(bù)可少的(de)文件
app.js app.json app.wxss
app.js: 腳本文件, 在(zài)這(zhè)裏監聽并處理小程序的(de)生命周期 以(yǐ)及全局變量
app.json:叫程序全局配置, 比如底部導航條樣式, 窗口背景色,默認标題等
app.wxss: 全局樣式表
官方文檔 https://mp.weixin.qq.com/debug/wxadoc/dev/index.html
案例包含知識點:
默認請求必須爲(wéi / wèi) https, 開發時(shí)手動開啓調試即可在(zài) http 環境下運行
上(shàng)拉加載 下拉刷新
分享轉發
自定義分享轉發按鈕
輪播圖循環滾動
模版的(de)使用
html解析轉換爲(wéi / wèi)小程序可解析(借助于(yú)wxParser)
具體的(de)不(bù)一一介紹, 看效果上(shàng)代碼
項目目錄列表
WX20170713-184232.png
1、頁面布局 底部導航 兩個(gè)分類
2、主頁面 頂部 輪播滾動 列表1、底部導航 由 app.json
頁面路徑
"pages": [
"pages/index/index",
"pages/detail/detail"
],
模版文件同樣需要(yào / yāo)在(zài)app.json 聲明, 首頁 列表 item 使用
"template": [
"template/homeCell"
],
配置底部導航
"tabBar": {
"color": "#7A7E83",
"selectedColor": "#ff3366",
"borderStyle": "black",
"backgroundColor": "#ffffff",
"list": [
{
"pagePath": "pages/index/index",
"iconPath": "image/nav_home_normal.png",
"selectedIconPath": "image/nav_home_selected.png",
"text": "數英"
},
{
"pagePath": "pages/logs/logs",
"iconPath": "image/nav_my_normal.png",
"selectedIconPath": "image/nav_my_selected.png",
"text": "我"
}
]
},
另外可以(yǐ)配置 全部網絡請求超時(shí) networkTimeout 具體參照 開發文檔
首頁
index.wxml
<import src="../../template/homeCell.wxml" />
//swiper 輪播控件 circular 屬性 true 無限輪播
<swiper class="banner" circular="true" indicator-dots="true" indicator-active-color="#ffffff" autoplay="true" interval="4000" duration="1000">
<block wx:for="{{imgUrls}}">
<swiper-item>
<image src="{{item.cover}}" class="slide-image" data-conType="{{item.conType}}" data-cover="{{item.cover}}" data-conId="{{item.conId}}" bindtap="clickAction"/>
</swiper-item>
</block>
</swiper>
<block wx:for="{{items}}">
<template is="homeCell" data="{{item}}"/>
</block>
//額外創建一個(gè)加載更多item
<view class="loadmore" >
<text class="more_title">正在(zài)加載...</text>
</view>
//imgUrls json 數組
//這(zhè)裏點擊圖片需要(yào / yāo)傳遞參數 詳情 類型 詳情頂部圖片 詳情 id
//傳參方式 data-conType="{{item.conType}}" 注意 獲取時(shí)候 小寫 data.contype 如下
clickAction: function (event) {
let data = https://www.wxapp-union.com/event.currentTarget.dataset;
console.log('****' + data.conid);
//點擊打開新的(de)頁面并 傳遞參數
wx.navigateTo({