鍍金池/ 問答/HTML/ 關(guān)于iview 移除節(jié)點(diǎn)報(bào)錯(cuò) 的問題

關(guān)于iview 移除節(jié)點(diǎn)報(bào)錯(cuò) 的問題

iview 報(bào)錯(cuò)內(nèi)容:

Uncaught TypeError: Failed to execute 'removeChild' on 'Node': parameter 1 is not of type 'Node'. at eval (iview.js?0536:31530)

bV7x6e?w=821&h=334

錯(cuò)誤截圖

bV7x6o?w=895&h=134

回答
編輯回答
命多硬

原因:
node_modules > iview > src > components > spin.js
remove (cb) {

    spin.visible = false;
    setTimeout(function() {
        spin.$parent.$destroy();
        //這個(gè)地方少了一個(gè)這個(gè)節(jié)點(diǎn)判斷,導(dǎo)致removeChild 里面的節(jié)點(diǎn)不存在,加上判斷即可
        if (document.getElementsByClassName('ivu-spin-fullscreen')[0]) {
            document.body.removeChild(document.getElementsByClassName('ivu-spin-fullscreen')[0]);
        }
        cb();
    }, 500);
},

但是因?yàn)檫@個(gè)是源碼,所以還同時(shí)需要修改打包后的文件:node_modules > iview > dist > iview.js

31529 行,改成如下:
if (document.getElementsByClassName('ivu-spin-fullscreen')[0]) {
            document.body.removeChild(document.getElementsByClassName('ivu-spin-fullscreen')[0]);
        }
        
        即可修復(fù),這個(gè)地方源碼部分不是很嚴(yán)謹(jǐn),沒有加判斷,導(dǎo)致在連續(xù)調(diào)用iview.Spin.hide()時(shí)會(huì)出問題,原因很簡(jiǎn)單
        給iview提issue,但是報(bào)錯(cuò),
  
2017年5月4日 04:04