這篇文章帶給大家的內容是關於微信小程式商城開發之https框架的搭建以及頂部和底部導航的實現,有一定的參考價值,有需要的朋友可以參考一下,希望對你有所幫助。 <br>
之前的小程式商城系列已經更新到購物車模組了但是很多讀者反映如何能夠更接近於實戰場景,動態的獲取數據並展示出來!那麼經過這段時間的準備我們開始來做新的微商城版本,該版本是完全按照工作場景來開發的。
登入註冊好的微信小程式官方帳號並登入平台->設定->開發設置,如下圖所示:
<br>
備註:https://100boot.cn 是已經認證過的域名,大家可以放心使用。
建立小程式專案可以參考文章微信小程式電商實戰-入門篇
#目录结构-pages --utils ---ajax.js
const api = 'https://100boot.cn/wxShop/';
wx.request({ method: opt.method || 'GET', url: api + opt.url, header: { 'content-type': 'application/json' // 默认值 }, data: opt.data, success: function (res) { if (res.data.code == 100) { if (opt.success) { opt.success(res.data); } } else { console.error(res); wx.showToast({ title: res.data.message, }) } } }) }module.exports.request = request
module.exports = { formatTime: formatTime, key: '开发者key' }微信小程式微商城:開發者key取得app.json #
{ "pages": [ "pages/home/home", "pages/cart/cart", "pages/detail/detail", "pages/classify/classify", "pages/mine/mine", "pages/index/index", "pages/logs/logs" ], "window": { "backgroundTextStyle": "light", "navigationBarBackgroundColor": "#f0145a", "navigationBarTitleText": "微商城", "backgroundColor": "#f0145a" }, "tabBar": { "color": "#858585", "selectedColor": "#f0145a", "backgroundColor": "#ffffff", "borderStyle": "#000", "list": [ { "pagePath": "pages/home/home", "iconPath": "images/home.png", "selectedIconPath": "images/home_select.png", "text": "首页" }, { "pagePath": "pages/classify/classify", "iconPath": "images/classify.png", "selectedIconPath": "images/classify_select.png", "text": "分类" }, { "pagePath": "pages/cart/cart", "iconPath": "images/cart.png", "selectedIconPath": "images/cart_select.png", "text": "购物车" }, { "pagePath": "pages/mine/mine", "iconPath": "images/mine.png", "selectedIconPath": "images/mine_select.png", "text": "我的" } ] } }app.wxss
.container { height: 100%; display: flex; flex-direction: column; align-items: center; justify-content: space-between; padding: 200rpx 0; box-sizing: border-box; }home.wxml
<!--导航条--> <view class="navbar"> <text wx:for="{{navbars}}" data-idx="{{index}}" class="item {{currentTab==index ? 'active' : ''}}" wx:key="unique" bindtap="navbarTap">{{item.navbarName}}</text> </view>home.wxss
page{ display: flex; flex-direction: column; height: 100%; } .navbar{ flex: none; display: flex; background: #fff; } .navbar .item{ position: relative; flex: auto; text-align: center; line-height: 80rpx; font-size:14px; } /* 顶部导航字体颜色 */ .navbar .item.active{ color: #f0145a; } /* 顶部指示条属性 */ .navbar .item.active:after{ content: ""; display: block; position: absolute; bottom: 0; left: 0; right: 0; height: 6rpx; background: #f0145a; }home.js引用ajax和utils公共js
const ajax = require('../../utils/ajax.js'); const utils = require('../../utils/util.js');頁面初始化導航資料
data: { navbars:null, currentTab: 0, },頁面初始化載入導航數據函數
/** * 生命周期函数--监听页面加载 */ onLoad: function (options) { var that = this; //加载navbar导航条 that.navbarShow(); },ajax取得導航資料
<br>
navbarShow:function(success){ var that = this; ajax.request({ method: 'GET', url: 'home/navBar?key=' + utils.key, success: data => { that.setData({ navbars: data.result }) console.log(data.result) } }) },實作效果如下
<br>##相關推薦:
微信小程式購物商城系統開發系列-工具篇 ##############################################################################################################################################################################################以上是微信小程式商城開發之https框架的建構以及頂部和底部導航的實現的詳細內容。更多資訊請關注PHP中文網其他相關文章!