本週主要內容以下javascript
這裏會涉及到的文件以下css
// utils -> util.js
const promisic = function (func) {
return function (params = {}) {
return new Promise((resolve, reject) => {
const args = Object.assign(params, {
success: (res) => {
resolve(res);
},
fail: (error) => {
reject(error);
}
});
func(args);
});
};
};
export {
promisic
}
複製代碼
import {config} from "../config/config";
import {promisic} from "./util";
class Http {
static async request({url, data, method='GET'}) {
const res = await promisic(wx.request)({
url:`${config.apiBaseUrl}${url}`,
data,
method,
header: {
appkey: config.appkey
}
})
return res.data
}
}
export {
Http
}
複製代碼
import {Http} from "../utils/http";
class Banner {
static locationB = 'b-1'
static async getHomeLocationB() {
return await Http.request({
url: `banner/name/${Banner.locationB}`
})
}
}
export {
Banner
}
複製代碼
onLoad: async function (options) {
this.initAllData();
},
async initAllData() {
const bannerB = await Banner.getHomeLocationB();
this.setData({
bannerB
})
},
複製代碼
npm i Lin-ui
html
Octotree: Chrome 插件
java
主題色更改&按需加載npm
// app.json
"usingComponents": {
"l-gird": "/miniprogram_npm/lin-ui/grid/index"
}
複製代碼
說明:lin-ui的宮格保留靈活性,而自定義的組件增強了宮格的方便性。json
代碼:小程序
// app.js 全局引入組件
"usingComponents": {
"l-grid": "/miniprogram_npm/lin-ui/grid/index",
"l-grid-item": "/miniprogram_npm/lin-ui/grid-item/index"
}
複製代碼
// category-grid 目錄
// index.js
// components/category-grid/index.js
Component({
// 從父組件接受grid數據
properties: {
grid: Array
}
})
複製代碼
/** components/category-grid/index.wxml **/
<view class="grid-container">
<l-grid l-class="inner-grid-container">
<block wx:for="{{grid}}">
<l-grid-item key="{{index}}" slot="{{index}}">
<view class="grid-item">
<image class="img" src="{{item.img}}"></image>
<text class="text">{{item.title}}</text>
</view>
</l-grid-item>
</block>
</l-grid>
</view>
css略...
複製代碼
// home 調用
<view>
<l-grid grid="{{grid}}"></l-grid>
</view>
//
複製代碼