Vue通過getAction的finally來(lái)最大程度避免影響主數(shù)據(jù)呈現(xiàn)問題
企業(yè)信息列表,查看某條記錄時(shí),彈窗頁(yè)里要求展示企業(yè)的用戶名,而用戶名字段不在企業(yè)表里。
為此,我們需要修改彈窗頁(yè)的渲染方法。
methods: { enterpriseInfo (record) { this.form.resetFields(); let product; if(record.product == ’HUICHUXING’){ product = ’惠出行’; }else if(record.product == ’BOSSKG’){ product = ’BOSS開工’; }else if(record.product == ’HUICHUXING,BOSSKG’ || record.product == ’BOSSKG,HUICHUXING’){ product = ’惠出行,BOSS開工’; }else{ product = ’業(yè)務(wù)未開通’; } this.model = Object.assign({}, record); this.model.product = product; this.visible = true; this.$nextTick(() => { this.form.setFieldsValue(pick(this.model,’enterpriseName’,’address’,’legalName’,’email’,’phone’,’userName’,’licensePic’, ’ipList’,’taxpayerNo’,’billAddress’,’bankName’,’bankCardNo’,’billPhone’,’product’)); }); }}
我的想法很清晰,recoord代表的是指定的企業(yè)的信息,在this.visible = true;前,給this.model.userName屬性重新賦值。
服務(wù)端接口很快實(shí)現(xiàn)了。不過,修改這個(gè)vue頁(yè)面的時(shí)候倒是吃力了。對(duì)于Jeecg-boot 的這套前段UI框架Ant Design Jeecg Vue,雖然已經(jīng)跟了幾個(gè)項(xiàng)目了,依然是一知半解。
自然是通過getAction來(lái)賦值了,然并卵。因?yàn)間etAction是異步請(qǐng)求,所以,肯定是不起作用了。
那么,該怎么辦呢?
一個(gè)小伙給出了方案,當(dāng)然,這也是我不得已而為之的方案————在getAction請(qǐng)求成功的方法里,給userName賦值,然后,再進(jìn)行頁(yè)面渲染。
methods: { enterpriseInfo (record) { ...... this.visible = true; getAction(’/ent/getEnterpriseLoginAcc?enterpriseId=’ + record.enterpriseId).then(response => { record.userName = response.result.loginAcc; this.model = Object.assign({}, record); this.$nextTick(() => { this.form.setFieldsValue(pick(this.model, ’enterpriseName’, ’address’, ’legalName’, ’email’, ’phone’, ’userName’, ’licensePic’, ’taxpayerNo’, ’billAddress’, ’bankName’, ’bankCardNo’, ’billPhone’, ’product’, ’industryType1’, ’industryType2’)); }); }); }}
這樣雖然實(shí)現(xiàn)了,但與我的想法有些不一致。怎么講?假如說(shuō),執(zhí)行g(shù)etAction出問題,那么整個(gè)頁(yè)面將無(wú)法呈現(xiàn)。這豈不因小失大!
后來(lái),問一個(gè)前端的同事,終于指點(diǎn)了迷津。 同事發(fā)的如下這個(gè)示意圖,提示可在1處、2處做文章。
當(dāng)然,經(jīng)過嘗試,發(fā)現(xiàn)類似getActionpostActionputAction除了.then()、.catch()外,還有finally()。那看來(lái),在沒有其他方案的情況下,————也許沒有其他方案了————這是最好的方案了,也符合我的期望。
methods: { enterpriseInfo (record) { ...... this.visible = true; this.$nextTick(() => { getAction(’/ent/getEnterpriseLoginAcc?enterpriseId=’+record.enterpriseId).then(res => { if(res.success) { this.model.userName = res.result.loginAcc; } }).finally(() => { // console.log('userName= '+this.model.userName) this.form.setFieldsValue(pick(this.model,’enterpriseName’,’address’,’legalName’,’email’,’phone’,’userName’,’licensePic’, ’ipList’,’taxpayerNo’,’billAddress’,’bankName’,’bankCardNo’,’billPhone’,’product’,’industryType1’,’industryType2’)); }); }); }}
到此這篇關(guān)于Vue通過getAction的finally來(lái)最大程度避免影響主數(shù)據(jù)呈現(xiàn)的文章就介紹到這了,更多相關(guān)vue getAction finally內(nèi)容請(qǐng)搜索好吧啦網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持好吧啦網(wǎng)!
相關(guān)文章:
1. vue實(shí)現(xiàn)移動(dòng)端返回頂部2. asp讀取xml文件和記數(shù)3. vue 驗(yàn)證兩次輸入的密碼是否一致的方法示例4. xml中的空格之完全解說(shuō)5. 多個(gè)SpringBoot項(xiàng)目采用redis實(shí)現(xiàn)Session共享功能6. python基于scrapy爬取京東筆記本電腦數(shù)據(jù)并進(jìn)行簡(jiǎn)單處理和分析7. python利用opencv實(shí)現(xiàn)顏色檢測(cè)8. CSS自定義滾動(dòng)條樣式案例詳解9. Python如何實(shí)現(xiàn)感知器的邏輯電路10. PHP實(shí)現(xiàn)基本留言板功能原理與步驟詳解
