vue2.x创建多页面程序的方法

虽然单页面应用越来越流行,但是多页面应用也有其应用领域,最典型的就是可以避免单页面应用变得过于庞大。

https://cli.vuejs.org/zh/config/#pages

给出了多页面应用的配置方法,只要在vue.config.js中增加配置就可以增加多页面的功能

  pages: {
    index: {
      // entry for the pages
      entry: 'src/dashboard/main.js',
      // the source template
      template: 'src/dashboard/index.html',
      // output as dist/index.html
      filename: 'index.html',
      // when using title option,
      // template title tag needs to be <title><%= htmlWebpackPlugin.options.title %></title>
      title: 'test'
      // chunks to include on this pages, by default includes
      // extracted common chunks and vendor chunks.
      // chunks: ['chunk-vendors', 'chunk-common', 'index']
    },
    frontEnd: {
      entry: 'src/frontEnd/main.js',
      template: 'src/frontEnd/index.html',
      filename: 'frontEnd.html',
      title: 'test - front'
    }
    // when using the entry-only string format,
    // template is inferred to be `public/subpage.html`
    // and falls back to `public/index.html` if not found.
    // Output filename is inferred to be `subpage.html`.
    // subpage: ''
  },

只要通过

http://website.com/index.html

http://website.com/frontEnd/index.html

就可以分别访问这两个不同的页面,如果浏览器和web服务器允许,后面的index.html也可以不输入

要注意的是,这是两个不同的页面,每个页面上的JS脚本运行产生的数据是隔离的,两个页面之间不可以共享数据。vuex也不行

如果一定要共享数据,那么不可以用JS来直接处理,而是要借助其他工具

比如localStorage可以在本地直接共享数据,不过要注意localStorage能存储的数据是十分有限的。

或者也可以利用服务器,比如用户验证的数据就可以通过服务器来共享,具体方法参考cookie和session

如果需要把单页面应用拆分成多页面应用,也就意味着这两个页面之间数据共享量不大,比如说用户登录信息非常小,所以这也不会因为数据传输导致特别严重的的问题。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值