監(jiān)聽此事件
Router.events.NavigationEnd<view class='tab'>
<view class='tab-menu'>
<view class='menu' wx:for="{{tabs}}" wx:key="{{index}}" data-tabidx="{{index}}" bindtap='switchTab'>
<text>{{item}}</text>
<view class='currentTab' wx:if="{{tabIdx === index}}"></view>
</view>
</view>
<swiper class='tab-content' current='{{tabIdx}}' bindchange='scrollTab'>
<swiper-item>
<view class='question-wrap'>
<view class='question-header'>
<text>[{{questions[current].type}}]</text>
<text class='total'><text class='current'>{{current+1}}</text>/{{questions.length}}</text>
</view>
<view class='title'>{{questions[current].title}}</view>
<view class='options'>
<view class='opt {{questions[current].right === index ? "right" : ""}}' wx:for="{{questions[current].options}}" wx:key="{{index}}">
<view class='tag'>
<image src='/icons/right.png' wx:if="{{questions[current].right === index}}"></image>
</view>
<view class='content'>{{item.content}}</view>
<text class='rate'>{{item.rate}}</text>
</view>
</view>
</view>
<view class='btns'>
<button disabled='{{current <= 0}}' bindtap="showPre">上一題</button>
<button disabled='{{current >= questions.length-1}}' bindtap="showNext">下一題</button>
</view>
</swiper-item>
<swiper-item>
<scroll-view scroll-y class='totalRank' lower-threshold="150" bindscrolltolower="getRank">
<view class='user' wx:for="{{ranks}}" wx:key="{{index}}">
<image src='{{item.img_url}}' class='avator'></image>
<view class='name'>{{item.name}}</view>
<view class='score'>{{item.score}}分</view>
<view class='order'>第{{item.no}}名</view>
</view>
</scroll-view>
</swiper-item>
</swiper>
</view>
page {
display: flex;
flex-direction: column;
height: 100%;
background: #fff;
font-size: 30rpx;
}
.tab {
flex: 1;
display: flex;
flex-direction: column;
}
.tab-content {
flex: 1;
overflow-y: auto;
}
.tab-menu {
height: 104rpx;
display: flex;
}
.currentTab {
background: #42c541;
height: 2rpx;
width: 132rpx;
position: absolute;
bottom: 20rpx;
}
.tab-menu .menu {
flex: 1;
text-align: center;
font-size: 28rpx;
display: flex;
align-items: center;
justify-content: center;
position: relative;
}
swiper-item {
overflow: auto;
}
.totalRank {
height: 100%;
}
.avator {
width: 60rpx;
height: 60rpx;
border-radius: 50%;
}
.user {
height: 88rpx;
display: flex;
align-items: center;
background: #f4f4f4;
padding: 0 43rpx;
margin: 30rpx 30rpx 0 30rpx;
border-radius: 10rpx;
box-sizing: border-box;
font-size: 24rpx;
}
.name, .score, .order {
flex: 1;
text-align: center;
}
.name{
margin-left: 50rpx;
overflow: hidden;
text-overflow: ellipsis;
white-space: nowrap;
}
.order {
color: #42c541;
text-align: right;
}
.question-wrap{
display: flex;
flex-direction: column;
margin: 0 30rpx;
border: 2rpx solid #DCDCDC;
border-radius: 10rpx;
box-sizing: border-box;
padding: 0 50rpx;
margin-top: 40rpx;
}
.question-header{
display: flex;
justify-content: space-between;
margin-top: 60rpx;
}
/* .question-wrap .options{
max-height: 600rpx;
overflow: auto;
} */
.question-header .total{
color: #E3E3E3;
}
.question-header .current{
color: #353535;
}
.question-wrap .title{
margin-top: 36rpx;
min-height: 178rpx;
}
.opt{
text-align: center;
position: relative;
background: #F0F0F0;
margin-bottom: 44rpx;
border-radius: 10rpx;
padding: 26rpx 20rpx;
display: flex;
align-items: center;
}
.opt image, .opt .tag{
width: 46rpx;
height: 34rpx;
}
.opt .rate{
min-width: 3em;
}
.opt .content{
flex: 1;
text-align: center;
}
.right{
background: #FF920B;
color: #FFF;
}
.btns{
display: flex;
margin-top: 60rpx;
position: fixed;
left: 0;
bottom: 0;
width: 100%;
height: 148rpx;
}
.btns button{
width: 260rpx;
height: 88rpx;
line-height: 88rpx;
text-align: center;
border-radius: 10rpx;
color: #FFF;
background: #41C629;
}
.btns button:active{
background: #179B16;
color: #A2D7A2;
}
.btns button[disabled]:active{
background: #F7F7F7;
color: #ACACAC;
}
Page({
data: {
tabs: [
'題目分析',
'成績排名'
],
ranks: [
{ name: '張三', score: 93 },
{ name: '李四', score: 60 },
{ name: '趙六', score: 8 },
{ name: '王五', score: 1000 },
{ name: '馮二', score: 45 }
],
questions: [],
current: 0,
tabIdx: 0
}
})同一個微信用戶,同一個小程序 storage 上限為 10MB。localStorage 以用戶維度隔離,同一臺設(shè)備上,A 用戶無法讀取到 B 用戶的數(shù)據(jù)。
知道了,他用來自動加載js文件的識別碼
@change="ceshi($event)" //這里用change比較好
ceshi(event){
//通過event.target.value可以拿到
}遇到了類似的問題 請問樓主怎么解決的
cookie過大會消耗服務(wù)器的帶寬,前提是你的帶寬很小,但是流量很大。
如果是一般的小網(wǎng)站流量小,到不要緊。
放cookie的有點是,可以在服務(wù)器端獲取到,并且可以在服務(wù)器端設(shè)置和修改cookie。
localstorage只能在客戶端使用js去修改。
不能引用相對路徑中的圖片,要放到assets文件夾中
全局錯誤處理和組件錯誤處理了解一下:https://cn.vuejs.org/v2/api/#errorHandlerhttps://cn.vuejs.org/v2/api/#errorCaptured
數(shù)據(jù)請求失敗提交至服務(wù)器,這個你得考慮下策略,特別是接受客戶端日志記錄的服務(wù)和數(shù)據(jù)請求服務(wù)在同一個終結(jié)點的時候。至于數(shù)據(jù)請求出錯如何做攔截,可以參考你依賴的http組件,比如 axios 可使用切片:
// Add a request interceptor
axios.interceptors.request.use(function (config) {
// Do something before request is sent
return config;
}, function (error) {
// Do something with request error
return Promise.reject(error);
});
// Add a response interceptor
axios.interceptors.response.use(function (response) {
// Do something with response data
return response;
}, function (error) {
// Do something with response error
return Promise.reject(error);
});/**
* 生命周期函數(shù)--監(jiān)聽頁面顯示
*/
onShow: function () {
}使用自帶的modal 不就好了嘛 我使用的沒有什么問題啊。
雙for循環(huán)
你的例子太過于復(fù)雜,什么第一層第二層的,看了老半天。
提煉你的要點:1、并發(fā) 2、高效率
1、并發(fā)
使用Promise.all就行了。比如:
await Promise.all([p1, p2, p3]);
或者直接執(zhí)行
for (let i = 0; i < datas.length; i++) {
let info = datas[i];
sleep(info).then((value) => {
console.log(value);
});
}
參考:https://segmentfault.com/q/10...
2、高效率。
何為高效率?只不過就是你想控制并發(fā)數(shù)罷了。要么自己實現(xiàn)計數(shù),要么使用第三方封裝好的。比如async,設(shè)置并發(fā)20個
var mapLimit = require("async/mapLimit");
mapLimit(datas, 20, async function(info, callback){
return await sleep(3);
}, function(err, result){
});
如果想弄清楚原理,這里貼一個函數(shù),可以控制并發(fā):
function map(arr, fn, concurrency) {
concurrency = concurrency || 1;
return new Promise(function(resolve, reject) {
var completed = 0;
var started = 0;
var running = 0;
var results = new Array(arr.length);
(function replenish() {
if (completed >= arr.length) {
return resolve(results);
};
while (running < concurrency && started < arr.length) {
running++;
started++;
var index = started - 1;
console.log('hd', arr[index], arr[index], index);
fn.call(arr[index], arr[index], index) // item,index
.then(function(result) {
// console.log('done');
running--;
completed++;
results[index] = result;
replenish();
})
.catch(reject);
}
})();
});
}
可以用1樓說的element的事件@blur
也可以用原生的方法加native
你沒有給出format 函數(shù)的原型,所以只能靠猜了,有一個時間格式化的函數(shù)庫叫format.js
提供了類似的方法,但是它把format 定義在原型鏈上的,所以調(diào)用的時候 是類似這樣date.format('mm-dd-YYYY')
又不知道你的subxxx 系列函數(shù)返回的值是什么,如果返回的直接是個Date Object
哪你的調(diào)用方式 應(yīng)該是
return subYears(now, age.age).format(dateFormat);
//如果不是,哪還要先轉(zhuǎn)換為Date對象第一個問題是你沒有在Icon這個標(biāo)簽中設(shè)置tintColor,當(dāng)然不會改變顏色。
第二個問題,試下將Tab高度寫的高點兒
jquery 源碼 絕對有用
推薦一本書 《單頁Web應(yīng)用 JavaScript從前端到后端》這本書不用框架,全用 oop 實現(xiàn)了一個 spa 應(yīng)用,即使你在使用框架 我都推薦這本書,把spa原理都講了出來。
這兩個看完水平絕對大漲,剩下的就是積累了吧
PS:
如果可以的話,建議還是學(xué)一門 oop語言 一門函數(shù)式語言,可以 從別的 語言 借鑒很多 經(jīng)驗
終于解決了。
git上面也有類似的問題,如果解決不了可以試著到
https://github.com/eslint/esl...
找解決方法
$timeout(funcyion(){},0)
北大青鳥APTECH成立于1999年。依托北京大學(xué)優(yōu)質(zhì)雄厚的教育資源和背景,秉承“教育改變生活”的發(fā)展理念,致力于培養(yǎng)中國IT技能型緊缺人才,是大數(shù)據(jù)專業(yè)的國家
達內(nèi)教育集團成立于2002年,是一家由留學(xué)海歸創(chuàng)辦的高端職業(yè)教育培訓(xùn)機構(gòu),是中國一站式人才培養(yǎng)平臺、一站式人才輸送平臺。2014年4月3日在美國成功上市,融資1
北大課工場是北京大學(xué)校辦產(chǎn)業(yè)為響應(yīng)國家深化產(chǎn)教融合/校企合作的政策,積極推進“中國制造2025”,實現(xiàn)中華民族偉大復(fù)興的升級產(chǎn)業(yè)鏈。利用北京大學(xué)優(yōu)質(zhì)教育資源及背
博為峰,中國職業(yè)人才培訓(xùn)領(lǐng)域的先行者
曾工作于聯(lián)想擔(dān)任系統(tǒng)開發(fā)工程師,曾在博彥科技股份有限公司擔(dān)任項目經(jīng)理從事移動互聯(lián)網(wǎng)管理及研發(fā)工作,曾創(chuàng)辦藍懿科技有限責(zé)任公司從事總經(jīng)理職務(wù)負責(zé)iOS教學(xué)及管理工作。
浪潮集團項目經(jīng)理。精通Java與.NET 技術(shù), 熟練的跨平臺面向?qū)ο箝_發(fā)經(jīng)驗,技術(shù)功底深厚。 授課風(fēng)格 授課風(fēng)格清新自然、條理清晰、主次分明、重點難點突出、引人入勝。
精通HTML5和CSS3;Javascript及主流js庫,具有快速界面開發(fā)的能力,對瀏覽器兼容性、前端性能優(yōu)化等有深入理解。精通網(wǎng)頁制作和網(wǎng)頁游戲開發(fā)。
具有10 年的Java 企業(yè)應(yīng)用開發(fā)經(jīng)驗。曾經(jīng)歷任德國Software AG 技術(shù)顧問,美國Dachieve 系統(tǒng)架構(gòu)師,美國AngelEngineers Inc. 系統(tǒng)架構(gòu)師。