npm init
npm install --save-dev weui-miniprogram
完成構建後能夠在目錄樹裏看到了miniprogram_npm以及裏面的weui-miniprogram組件文件夾
html
最近的ui組件庫新增了官方的自定義導航,這個方便了不少,不再用本身動手作,以index頁面爲例
index.wxml裏引入組件:git
<!--WXML示例代碼--> <mp-navigation-bar loading="{{loading}}" show="{{show}}" animated="{{animated}}" color="{{color}}" background="{{background}}" title="自定義導航" back="{{true}}"></mp-navigation-bar>
index.json配置github
{ "usingComponents": { "mp-navigation-bar": "/miniprogram_npm/weui-miniprogram/navigation-bar/navigation-bar" }, "navigationStyle": "custom" }
app.wxss引入全局樣式npm
@import '/miniprogram_npm/weui-miniprogram/weui-wxss/dist/style/weui.wxss';
這個自定義導航包括了不少用法,隱藏標題只保留膠囊按鈕、自定義返回頁面數等等json
還有其餘好用的組件小程序
js 中引入 npm 包微信
const myPackage = require('packageName') const packageOther = require('packageName/other')
json配置微信開發
{ "usingComponents": { "myPackage": "packageName", "package-other": "packageName/other" } }