【问题标题】:Why vue replaces static page title with Vue App为什么 vue 用 Vue App 替换静态页面标题
【发布时间】:2020-12-23 15:32:36
【问题描述】:

我正在做一个非常简单的单页 html 项目。假设从外部本地文件加载数据并生成一些图形/图表/等的是 static.html。我正在使用 Vue,但我被卡住了。

  1. 我的 public/index.html 有如下默认内容

<!DOCTYPE html>
<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">
        <link rel="icon" type="image/png" href="img/favicon/black.png">
        <title>DummyTitle</title>
    </head>
    <body>
        <noscript>
            <strong>We're sorry but <%= htmlWebpackPlugin.options.title %> doesn't work properly without
                JavaScript enabled. Please enable it to continue.</strong>
        </noscript>
        <div id="app"></div>
        <!-- built files will be auto injected -->
    </body>
</html>

还有一些我不明白的地方。 yarn build 后 dist/index.html 内容如下

<!DOCTYPE html>
<html>

<head>
    <meta charset=utf-8>
    <meta http-equiv=X-UA-Compatible content="IE=edge">
    <meta name=viewport content="width=device-width,initial-scale=1">
    <title>Vue App</title>
    <link href=css/app.9288aca6.css rel=preload as=style>
    <link href=js/app.2c3ec05b.js rel=preload as=script>
    <link href=js/chunk-vendors.6fa5766d.js rel=preload as=script>
    <link href=css/app.9288aca6.css rel=stylesheet>
</head>

<body>
    <div id=app></div>
    <script src=js/chunk-vendors.6fa5766d.js></script>
    <script src=js/app.2c3ec05b.js></script>
</body>

</html>

到底发生了什么?为什么标题已更改为 Vue App 以及 favicon 在哪里?我一直在寻找类似的问题和问题,但没有发现什么可以帮助我理解为什么会这样。

【问题讨论】:

  • 你在项目根目录中有public 文件夹吗?另外,你在使用 webpack 吗?
  • 当然,我猜这是因为我已将 index.html 的名称更改为 dummy.html,如此处所述 link 通过添加到 vue.config.js module.exports = { indexPath: 'dummy.html' }
  • 好的。我需要查看确切的配置和项目结构。如果你的代码在某个地方,我可以看看它是否不起作用

标签: javascript html vue.js


【解决方案1】:

首先,我认为将public目录中的html文件从index重命名为dummy不应该有任何具体原因。

  1. 如果您只需要在dist 文件夹中将输出名称为dummy,则将public 文件夹中的html 文件重命名为索引并在vue.config.js 中使用它。这将解决问题。

    module.exports = {
     publicPath: '/',
     indexPath: 'dummy.html'
    }
    
  2. 如果您需要在项目结构和dist 中将html 文件命名为dummy,只需在vue.config.js 中使用它即可。这将解决标题问题。参考这个官方文档链接Vue Config Docs Link

     module.exports = {
      pages: {
          index: {
            // entry for the page
            entry: 'src/main.js',
            // the source template
            template: 'public/dummy.html',
            // output as dist/index.html
            filename: 'dummy.html'
          }
      },
      publicPath: '/',
      indexPath: 'dummy.html'
    }
    

【讨论】:

    猜你喜欢
    • 2021-08-13
    • 2018-10-04
    • 2018-10-27
    • 2021-05-21
    • 1970-01-01
    • 1970-01-01
    • 2020-05-09
    • 2012-07-08
    • 2018-12-09
    相关资源
    最近更新 更多