使用axios.all和axios.spread處理並發請求


點擊機構樹查詢人員信息和行政區域數據,但他們是兩個接口。

template結構

        <div class="organize-view">
            <el-tree
                :data="treeData"
                :props="defaultProps"
                ref="tree"
                :show-checkbox="false"
                :load="loadSubOrg"
                lazy
                @node-click="getData"
                :expand-on-click-node='false'
                :default-expand-all='false'>
                    <span class="custom-tree-node" slot-scope="{ node}">
                        <span class="tree-node_left">{{node.label}}</span>
                    </span>
            </el-tree>
        </div>

  

        //點擊機構獲取某機構人員數據
        getData(node) {
            // let orgId = node.id;
            let that = this;
            this.paulId = node.id;
            this.$axios.all([ that.getHaveUser(), that.getDistrict()])
                .then(that.$axios.spread((resUser, resDist) => {
                    console.log(resUser.users, '人員')
                    this.tableData = resUser.users;
                    console.log(resDist.district, '行政區域')
                }))
        },
        getHaveUser() {
            return this.$axios({
                    method: 'post',
                    url: this.$api.personManage.findUsersHaveResources,
                    data: { "orgId" : this.paulId}
                })
        },
        getDistrict() {
            return this.$axios({
                    method: 'get',
                    url: this.$api.organization.findByOrgId + '/' + this.paulId,
                })
        },

  

  


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM