Skip to content
调试模式添加
html
<!doctype html>
<html lang="zh-CN">
<head>
  <meta charset="UTF-8" />
  <title>Document</title>
</head>
<body>
  <h1>仅当 URL 带 ?debug=1 时才加载 VConsole</h1>

  <script>
    // 根据 URL 参数 自行控制
    const isDebug = /[?&]debug=1/.test(location.search);

    if (isDebug) {
      // 动态插入脚本,加载完成后再实例化
      const script = document.createElement('script');
      script.src = 'https://npm.webcache.cn/vconsole@latest/dist/vconsole.min.js';
      script.onload = () => {
        window.vConsole = new VConsole();
        console.log('VConsole 已加载');
      };
      document.head.appendChild(script);
    }
  </script>
</body>
</html>