如題,在異步加載獲取頁面數據時,有時會調用其餘組件,當在傳參時有時並非全部參數都已加載。異步
異步加載數據獲取異常的解決方法:setInterval()函數
setInterval()這個方法可按照指定的週期(以毫秒計)來調用函數或計算表達式。 this
setInterval(x(),y); class
x()表明你調用的方法,方法
y是每隔多長時間調用一次x()方法 數據
例如: setInterval(x(),1000);
每隔1秒調用一次x()方法 異常
以下: var stv = setInterval(() => {},1000);di
在{}的方法裏面調用clearInterval(stv ) 方法,把返回值做爲參數。時間
示例代碼以下:ant
var stv = setInterval(() => {
var id = this.id;
if(id !=0 && id != undefined){
clearInterval(stv);
//todo
}
},1000);
後記:There are mements in life when you miss someone so much that you just want to pick them from your dreams and hug them for real!
Dream what you want to dream,go where you want to go,be what you want to be,
because you have only one life and one chance to do all the things you want to do.