【问题标题】:How to fix browser in live server using visual studio?如何使用 Visual Studio 修复实时服务器中的浏览器?
【发布时间】:2021-10-18 01:20:48
【问题描述】:

因为我正在学习 freecodecamp 上的编码教程,所以我第一次接触到 Mac 的 Visual Studio Code 编码和使用。我安装了 VSC 和 live server 和 Chrome 浏览器扩展,但是当我去 live server 时出现错误:

// = 0 ? '&' : '?') + '_cacheOverride=' + (new Date().valueOf()); } parent.appendChild(elem); } } var 协议 = window.location.protocol === 'http:' ? 'ws://' : 'wss://'; var 地址 = 协议 + window.location.host + window.location.pathname + '/ws'; var socket = new WebSocket(地址); socket.onmessage = function (msg) { if (msg.data == 'reload') window.location.reload();否则 if (msg.data == 'refreshcss') refreshCSS(); }; if (sessionStorage && !sessionStorage.getItem('IsThisFirstTime_Log_From_LiveServer')) { console.log('Live reload enabled.'); sessionStorage.setItem('IsThisFirstTime_Log_From_LiveServer', true); } })(); } else { console.error('升级您的浏览器。此浏览器不支持 WebSocket 进行实时重载。'); } // ]]>

我在 Mozilla 上尝试过,但扩展程序甚至无法安装为插件损坏 - https://share.getcloudapp.com/WnuG42w2

在 Firefox 上尝试不使用扩展程序并得到与 Chrome 相同的错误。

任何帮助将不胜感激!

【问题讨论】:

    标签: visual-studio-code


    【解决方案1】:

    最近,我在使用 Visual Code 时遇到了同样的问题。这是一个“实时服务器”错误。 Live Server 尝试将一些代码作为注释注入到原始代码中,从而导致此错误。刷新实时服务器将使一切恢复正常。

    【讨论】:

      【解决方案2】:

      尝试用结束标签关闭标签。例如替换:

      <textarea
        id="message"
        name="message"
        cols="30"
        rows="10"
      />
      

      与:

      <textarea
        id="message"
        name="message"
        cols="30"
        rows="10"
      ></textarea>
      

      这实际上对我有用。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2019-05-31
        相关资源
        最近更新 更多