【问题标题】:How to create a multipage Vue.js application with pages on nested subdirectories by modifying vue.config.js?如何通过修改 vue.config.js 在嵌套子目录上创建一个多页面 Vue.js 应用程序?
【发布时间】:2020-11-06 02:52:39
【问题描述】:

我有一个多页 Vue.js 应用程序,其中包含域/法律的工作页面;域/提交;等等。我在 Vue.js 的 pages 的帮助下实现了这一点(即自定义 vue.config.js

换句话说,我很好地完成了上述工作。

我现在正尝试在新的子目录级别下实现更多的嵌套页面(除了上面我已经拥有的那些)。即

  • 域/org/profile1
  • 域/org/profile2
  • 域/org/profile3

有什么方法可以通过自定义 vue.config.js 来完成这项工作?

当前尝试vue.config.js 代码:

module.exports = {
  pages: {
    index: {
      entry: "./src/pages/home/main.js",
      template: "public/index.html",
      title: "Home",
      chunks: ["chunk-vendors", "chunk-common", "index"],
    },
    legal: {
      entry: "./src/pages/legal/main.js",
      template: "public/index.html",
      title: "Legal",
      chunks: ["chunk-vendors", "chunk-common", "legal"],
    },
    submit: {
      entry: "./src/pages/submit/main.js",
      template: "public/index.html",
      title: "Submit",
      chunks: ["chunk-vendors", "chunk-common", "submit"],
    },
    org: {
      digitalocean: {
        entry: "./src/pages/org/digitalocean/main.js",
        template: "public/index.html",
        title: "Digital Ocean",
        chunks: ["chunk-vendors", "chunk-common", "digitalocean"],
      },
    },
  },
};

及文件结构:

src
-assets
-components
-pages
--home
    App.vue
    main.js
--legal
    App.vue
    main.js
--submit
    App.vue
    main.js
--org
---digitalocean
     App.vue
     main.js

这给了我错误:

Invalid options in vue.config.js: child "pages" fails because [child "org" fails because ["org" must be a string, "org" must be an array, child "entry" fails because ["entry" is required]]]

非常欢迎您提供关于如何通过修改 vue.config.js 使嵌套页面工作的指针!

【问题讨论】:

  • 嗯,你不想使用 vue-router?
  • @HimanshuPant 感谢您的参与!如果我不需要使用 vue-router,我想通过仅使用 vue.config.js 来简化它。您认为有什么方法可以实现吗?
  • 文档说任何其他属性都传递给 html-webpack-plugin 试试这个 ``` module.exports = { pages: { index: { entry: "./src/pages/home/ main.js",模板:"public/index.html",标题:"Home",块:["chunk-vendors","chunk-common","index"],页面:{ digitalocean: { entry:" ./src/pages/org/digitalocean/main.js”,模板:“public/index.html”,标题:“Digital Ocean”,块:[“chunk-vendors”,“chunk-common”,“digitalocean” ], }, } } }, }; ```
  • 感谢您的建议:执行您的建议的错误是:Invalid options in vue.config.js: child "pages" fails because [child "pages" fails because ["pages" must be a string, "pages" must be an array, child "entry" fails because ["entry" is required]]]
  • 任何其他指针欢迎@HimanshuPant :)

标签: vue.js vue-cli vue-cli-3 multipage multi-page-application


【解决方案1】:

我只用vue.config.js 解决了这个问题。注:强大的小东西vue.config.js是:

├── src
│   ├── assets
│   │   └── logo.png
│   ├── components
│   │   └── HelloWorld.vue
│   └── pages
│       ├── home
│       │   ├── App.vue
│       │   ├── cache.js
│       │   └── main.js
│       ├── legal
│       │   ├── App.vue
│       │   └── main.js
│       ├── org
│       │   ├── digitalocean
│       │   │   ├── App.vue
│       │   │   └── main.js
│       │   └── intercom
│       └── submit
│           ├── App.vue
│           └── main.js
└── vue.config.js

还有vue.config.js:

module.exports = {
  pages: {
    index: {
      entry: "./src/pages/home/main.js",
      template: "public/index.html",
      filename: "index.html",
      title: "Home",
      chunks: ["chunk-vendors", "chunk-common", "index"],
    },
    legal: {
      entry: "./src/pages/legal/main.js",
      template: "public/index.html",
      filename: "legal.html",
      title: "Legal",
      chunks: ["chunk-vendors", "chunk-common", "legal"],
    },
    submit: {
      entry: "./src/pages/submit/main.js",
      template: "public/index.html",
      filename: "submit.html",
      title: "Submit",
      chunks: ["chunk-vendors", "chunk-common", "submit"],
    },
    "org/digitalocean": {
      entry: "./src/pages/org/digitalocean/main.js",
      template: "public/index.html",
      filename: "org/digitalocean.html",
      title: "Digital Ocean",
      chunks: ["chunk-vendors", "chunk-common", "org/digitalocean"],
    },
  },
};

【讨论】:

  • 投放时如何找到页面URL?
  • 仍然无法与 webpack devserver 一起使用。
猜你喜欢
  • 2021-03-19
  • 1970-01-01
  • 2013-05-30
  • 2023-03-28
  • 1970-01-01
  • 1970-01-01
  • 2022-07-02
  • 1970-01-01
  • 2020-05-27
相关资源
最近更新 更多