wordpress主題修改ftp寧波seo網(wǎng)絡(luò)推廣
場(chǎng)景
點(diǎn)擊按鈕,檢測(cè)到未登錄,直接跳轉(zhuǎn)到登錄頁(yè),登錄成功后,返回頁(yè)面繼續(xù)執(zhí)行剛才的點(diǎn)擊事件
思路
在跳轉(zhuǎn)時(shí)用一個(gè)隊(duì)列存儲(chǔ)該事件,登錄成功后執(zhí)行隊(duì)列里的事件
隊(duì)列
class Queue {constructor() {this.task = []}clear() {this.task = []}push(item, isReset = true) {if (isReset) {this.task = []}this.task.push(item)}run() {this.task.forEach((item) => {item.callback.apply(null, item.params)})this.task = []}
}//可以使用全局變量,也可以使用單例模式
export default class StaticStore {static taskQueue = new Queue()
}
const handleClick = (params) => {if (!token) {navigate('Login')StaticStore.taskQueue.push({ callback: handleClick, [params] })return}console.log('完成')}
const login = async () => {await axios.get('xxx')Toast.show('登錄成功')navigation.goBack();StaticStore.taskQueue.run()
}