1

当我在浏览器中打开我的 vue 应用程序的 URL 时,它会加载应用程序。但是,当我尝试在终端中使用 curl 调用 URL 时,它会返回错误

CURL https://vue-app-url.com/

输出:

<html lang="en">
  <head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width,initial-scale=1.0">
    <!--[if IE]><link rel="icon" href="/favicon.ico"><![endif]-->
    <title>VUE APP</title>
  <link href="/app.js" rel="preload" as="script"><link rel="icon" type="image/png" sizes="32x32" href="/img/icons/favicon-32x32.png"><link rel="icon" type="image/png" sizes="16x16" href="/img/icons/favicon-16x16.png"><link rel="manifest" href="/manifest.json"><meta name="theme-color" content="#4DBA87"><meta name="apple-mobile-web-app-capable" content="no"><meta name="apple-mobile-web-app-status-bar-style" content="default"><meta name="apple-mobile-web-app-title" content="app-vue"><link rel="apple-touch-icon" href="/img/icons/apple-touch-icon-152x152.png"><link rel="mask-icon" href="/img/icons/safari-pinned-tab.svg" color="#4DBA87"><meta name="msapplication-TileImage" content="/img/icons/msapplication-icon-144x144.png"><meta name="msapplication-TileColor" content="#000000"></head>
  <body>
    <noscript>
      <strong>We're sorry but app-vue doesn't work properly without JavaScript enabled. Please enable it to continue.</strong>
    </noscript>
    <div id="app"></div>
    <!-- built files will be auto injected -->
  <script type="text/javascript" src="/app.js"></script></body>
</html>
4

1 回答 1

0

因为curl只会加载标记,这似乎是正确的输出。如果您将 a 添加noscript到通过 Javascript 加载或添加“真实”内容的页面,那么您将通过 curl 获得 noscript。由于 curl 没有加载额外的资源。

也试试这个命令,你可能会得到更好的输出:

curl --location https://vue-app-url.com/

或者

curl --user-agent "Mozilla/5.0 (X11; Linux x86_64; rv:60.0) Gecko/20100101 Firefox/81.0" https://vue-app-url.com/

还可以尝试删除您的noscriptjust 以通过 curl 对其进行测试。

更新(更好的例子):

如果你在 html 中添加一个 vue 组件,可以说:

<feedback-form>Some feedback</feedback-form>

curl 将呈现:

<div id="app"><feedback-form>Some feedback</feedback-form></div>

因此,您的应用程序一切正常,只是 JS 没有被解析。它就像您页面的源代码而不是您的开发工具中的代码(已解析)。

于 2021-04-13T07:59:25.757 回答