一:動態(tài)設(shè)置導(dǎo)航條
分享者:HaiJing1995,來自原文地址
我們知道微信小程序中設(shè)置導(dǎo)航條可以直接在json文件中設(shè)置 "navigationBarTitleText" = "String" 就可以了
但是我們有時可能需要根據(jù)不同的情況動態(tài)設(shè)置導(dǎo)航條。
微信小程序給我們提供了一個方法
-
setNavigationBarTitle({
-
title: "string",
-
success: funciton(res){
-
...
-
}
-
})
注意這個setNavigationBarTitle方法一定要寫在onReady方法中,因為這是頁面才完全渲染完成。通常在onLoad中我們是不能對UI進(jìn)行操作的。
setNavigationBarTitle方法中的title如果我們像這樣設(shè)置靜態(tài)字符串的話是起不到動態(tài)設(shè)置導(dǎo)航條的作用 的。 我們可以從onLoad中獲取到一個動態(tài)變量,那如何將這個變量從onLoad中傳遞給onReady方法呢? 我們可以在onLoad中通過this.setData({key: value})將這個變量傳遞給data,在onReady中再通過this.data.key獲得這個變量。
二:動態(tài)加載數(shù)據(jù)
分享者:冉然,來自原文地址 1、首先要寫在js里定義一個全局變量
-
data: {
-
datalist: []
-
},
2、請求數(shù)據(jù)加載,獲得整個數(shù)組信息
-
wx.request({
-
url: httpUrl,
-
data: {},
-
success: function (res) {
-
that.setData({
-
datalist: res.data.courses
-
})
-
},
3、在.wxml中調(diào)用 數(shù)組的調(diào)用用:wx:for="{{datalist}}" 數(shù)組中的單個變量調(diào)用用:{{item.courseTitle}} 數(shù)組中有域名的單個變量的調(diào)用用:https://360fast-edu.com{{item.pictureUrl}}
三:用ES6Promise.all批量上傳文件
分享者:馬小云,來自原文地址 客戶端
-
Page({
-
onLoad: function() {
-
wx.chooseImage({
-
count: 9,
-
success: function({ tempFilePaths }) {
-
var promise = Promise.all(tempFilePaths.map((tempFilePath, index) => {
-
return new Promise(function(resolve, reject) {
-
wx.uploadFile({
-
url: 'https://www.mengmeitong.com/upload',
-
filePath: tempFilePath,
-
name: 'photo',
-
formData: {
-
filename: 'foo-' + index,
-
index: index
-
},
-
success: function(res) {
-
resolve(res.data);
-
},
-
fail: function(err) {
-
reject(new Error('failed to upload file'));
-
}
-
});
-
});
-
}));
-
promise.then(function(results) {
-
console.log(results);
-
}).catch(function(err) {
-
console.log(err);
-
});
-
}
-
});
-
}
-
});
服務(wù)端
-
<?php
-
use IlluminateHttpRequest;
-
Route::post('/upload', function (Request $request) {
-
if ($request->photo->isValid()) {
-
$request->photo->storeAs('images/foo/bar/baz', $request->filename . '.' . $request->photo->extension());
-
return ['success' => true, 'index' => $request->index];
-
}
-
});
|