在线观看不卡亚洲电影_亚洲妓女99综合网_91青青青亚洲娱乐在线观看_日韩无码高清综合久久

鍍金池/ 問答/HTML/ 在React中重新請求腳本修改全局變量不生效,但是在控制臺手動請求就生效是怎么回

在React中重新請求腳本修改全局變量不生效,但是在控制臺手動請求就生效是怎么回事?

我在項(xiàng)目中的登陸頁的componentDidMount中將window._vds設(shè)置成初始值,然后想把已經(jīng)加載進(jìn)來的腳本去掉,(之前登錄進(jìn)系統(tǒng)之后會有加載進(jìn)來的js文件)然后重新加載,按理說,那個重新加載進(jìn)來的js文件會將window._vds處理成一個其它的對象,但是我這段代碼執(zhí)行過后并沒有使window._vds變成想要的對象結(jié)果。它還是一個初始定義的數(shù)組:

componentDidMount() {
    // 給growingIO設(shè)置初始值
    const script = document.getElementById('vds');
    if (script) {
      window._vds = [['setAccountId', 'xxx']];
      script.parentNode.removeChild(script);
      var vds = document.createElement('script');
      vds.type = 'text/javascript';
      vds.async = true;
      vds.id = 'vds';
      vds.src = ('https:' == document.location.protocol ? 'https://' : 'http://') + 'dn-growing.qbox.me/vds.js';
      var s = document.getElementsByTagName('script')[0];
      s.parentNode.insertBefore(vds, s);
    }
  }

圖片描述

但是如果在控制臺中手動執(zhí)行一下下面代碼中的內(nèi)容:

window._vds = [['setAccountId', 'xxx']];
const script = document.getElementById('vds');
if (script) {
  script.parentNode.removeChild(script);
  var vds = document.createElement('script');
  vds.type = 'text/javascript';
  vds.async = true;
  vds.id = 'vds';
  vds.src = ('https:' == document.location.protocol ? 'https://' : 'http://') + 'dn-growing.qbox.me/vds.js';
  var s = document.getElementsByTagName('script')[0];
  s.parentNode.insertBefore(vds, s);
}

這個window._vds就如愿變成了對象,可能是怎么回事呢?

圖片描述

回答
編輯回答
還吻

只是script標(biāo)簽換了一下,沒有真正請求那個js

2018年3月9日 05:27