鍍金池/ 問答/HTML/ 如果用Generator 函數(shù)該怎么改寫如下代碼?

如果用Generator 函數(shù)該怎么改寫如下代碼?

handleCurrentChange (val) {
    this.loading = true
    rtumQueryUser({
        body: {
            pageSize: 20,
            pageNum: val,
            userName: this.queryForm.userName
        }
    })
    .then(res => {
        this.loading = false
        if (res.data.code === '20000') {
            this.userList = res.data.result.data
            this.totalPage = res.data.result.totalPage
            this.currentPage = res.data.result.pageNum
            this.pageSize = res.data.result.pageSize
            // this.expandRowKeys.push(this.userList[0].userId)
        } else {
            this.$message(res.data.message)
        }
    })
    .catch(err => {
        this.loading = false
        this.$message.error(err.message)
    })
}

代碼如上,想達(dá)到的效果是在 this.userList = res.data.result.data 使表格數(shù)據(jù)被渲染之后,再調(diào)用 this.expandRowKeys.push(this.userList[0].userId) 使表格的第一行展開,如果用Generator函數(shù)該怎么改寫?也歡迎其他方法,多多益善,對(duì)這類問題不太會(huì)解決,謝謝!

回答
編輯回答
陌南塵

Generator 有能力,把所有“回調(diào)”改成真正的“返回”。

以前是:

asyncCall().then(function(response){ console.log(response) });

可以改成:

var response = yield gen.Task(asyncCall);
console.log(response);

細(xì)節(jié):https://www.zouyesheng.com/js...

2017年6月11日 17:45