Fork me on github

函数return

 findCategory(id) {
// this.Category=[{id:1,name:'ljj'},{id:2,name:'wmy'}]
                    var ar = this.Category.find(function (elem) {
                        return elem.id == id;
                    });
                    return ar.name
                },

 法2

 findCategory(id) {
                    var value
                    this.Category.forEach(item => {
                        if (item.id == id) {
                            value = item.name
                        }     
                    })
                    return value
                },

^(* ̄(oo) ̄)^:foreach不可以内部直接return

异步函数,async/await,promise目前return出的都是[promise object]

posted @ 2022-09-08 14:52  我の前端日记  阅读(20)  评论(0编辑  收藏  举报
Copyright © 2021 LinCangHai
Powered by .NET 5.0 on Kubernetes