本周主要内容以下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>
//
复制代码