搜尋
首頁微信小程式小程式開發微信小程式商城開發之https框架的建構以及頂部和底部導航的實現

這篇文章帶給大家的內容是關於微信小程式商城開發之https框架的搭建以及頂部和底部導航的實現,有一定的參考價值,有需要的朋友可以參考一下,希望對你有所幫助。 <br>

之前的小程式商城系列已經更新到購物車模組了但是很多讀者反映如何能夠更接近於實戰場景,動態的獲取數據並展示出來!那麼經過這段時間的準備我們開始來做新的微商城版本,該版本是完全按照工作場景來開發的。

小程式https網域設定

登入註冊好的微信小程式官方帳號並登入平台->設定->開發設置,如下圖所示:

<br>

備註:https://100boot.cn 是已經認證過的域名,大家可以放心使用。

建立小程式專案並封裝ajax請求

建立小程式專案可以參考文章微信小程式電商實戰-入門篇

新ajax.js
#目录结构-pages
--utils
---ajax.js
聲明api 全域變數呼叫位址
const api = &#39;https://100boot.cn/wxShop/&#39;;
封裝request請求
wx.request({    
    method: opt.method || &#39;GET&#39;,    
    url: api + opt.url,    
    header: {      
        &#39;content-type&#39;: &#39;application/json&#39; // 默认值
    },    
    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
##設定開發者key
開啟utils/util.js,增加key

module.exports = {
  formatTime: formatTime,
  key: &#39;开发者key&#39;
}

微信小程式微商城:開發者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 ? &#39;active&#39; : &#39;&#39;}}" 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(&#39;../../utils/ajax.js&#39;);
const utils = require(&#39;../../utils/util.js&#39;);

頁面初始化導航資料

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: &#39;GET&#39;,      
        url: &#39;home/navBar?key=&#39; + utils.key,      
        success: data => {
        that.setData({          
            navbars: data.result
        })        
        console.log(data.result)
      }
    })
  },

實作效果如下

<br>##相關推薦:

微信小程式購物商城系統開發系列-工具篇

<br>

##############################################################################################################################################################################################

以上是微信小程式商城開發之https框架的建構以及頂部和底部導航的實現的詳細內容。更多資訊請關注PHP中文網其他相關文章!

陳述
本文內容由網友自願投稿,版權歸原作者所有。本站不承擔相應的法律責任。如發現涉嫌抄襲或侵權的內容,請聯絡admin@php.cn

熱AI工具

Undresser.AI Undress

Undresser.AI Undress

人工智慧驅動的應用程序,用於創建逼真的裸體照片

AI Clothes Remover

AI Clothes Remover

用於從照片中去除衣服的線上人工智慧工具。

Undress AI Tool

Undress AI Tool

免費脫衣圖片

Clothoff.io

Clothoff.io

AI脫衣器

Video Face Swap

Video Face Swap

使用我們完全免費的人工智慧換臉工具,輕鬆在任何影片中換臉!

熱門文章

熱工具

ZendStudio 13.5.1 Mac

ZendStudio 13.5.1 Mac

強大的PHP整合開發環境

記事本++7.3.1

記事本++7.3.1

好用且免費的程式碼編輯器

VSCode Windows 64位元 下載

VSCode Windows 64位元 下載

微軟推出的免費、功能強大的一款IDE編輯器

SublimeText3 Linux新版

SublimeText3 Linux新版

SublimeText3 Linux最新版

SublimeText3 英文版

SublimeText3 英文版

推薦:為Win版本,支援程式碼提示!