美文网首页前端开发
vue多页应用配置

vue多页应用配置

作者: 颂温暖 | 来源:发表于2019-06-14 14:27 被阅读50次

vue脚手架创建的项目都是单页面应用
但是有一些场景下我们需要使用多页面应用(比如一个系统的后端和前端要分为不同的页面应用,或者同一个服务器下的不用的项目)
网上也找了一些资料,自己配置了下,目前来说是成功的
配置如下:
在vue.config.js中添加

pages: {
    index: {
      // page 的入口
      entry: 'src/modules/mobile/main.js',
      // 模板来源就是在public里面创建的入口文件名
      template: 'public/index.html',
      // 编译后在 dist文件夹中的输出文件名,可选项,省略时默认与模块名一致
      filename: 'index.html',
      // 当使用 title 选项时,
      // template 中的 title 标签需要时 <title><%= htmlWebpackPlugin.options.title %></title>
      title: '项目标题',
      // 在这个页面中包含的块,默认情况下会包含
      // 提取出来的通用 chunk 和 vendor chunk。
      chunks: ['chunk-vendors', 'chunk-common', 'index']
    },
    // 当使用只有入口的字符串格式时,也就是只有entry属性时,直接用字符串表示模块入口
    elive: 'src/modules/elive/elive.js'
  }

如有了解详细请去cli3官网配置文件里面查询

项目目录是这样


image.png

而且项目中的public目录要新建这样多页面elive.html,图片和内容如下:


image.png
elive.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, maximum-scale=1, minimum-scale=1, user-scalable=no" />
    <title><%= htmlWebpackPlugin.options.title %></title>
</head>
<body>
<div id="elive"></div>
</body>
</html>

至于多页面中的elive入口文件配置代码和目录:

elive.js

import Vue from 'vue'
import Elive from './Elive.vue'
import router from './router'
import store from './store'
import http from '../elive/http/http'
import VueAweSomeSwiper from 'vue-awesome-swiper'
import 'swiper/dist/css/swiper.css'
import VueLazyload from 'vue-lazyload'

Vue.prototype.$http = http
Vue.config.productionTip = false
Vue.use(require('vue-wechat-title'))
Vue.use(VueAweSomeSwiper)
Vue.use(VueLazyload, {
  preLoad: 1.3,
  // error: 'dist/error.png',
  loading: require('./assets/img/load.gif'),
  attempt: 1
})

new Vue({
  router,
  store,
  render: h => h(Elive)
}).$mount('#elive')

image.png

上图的mobile就是vue单页应用的配置,elive其实跟mobile配置一样,只是需要修改elive绑定的组件更换就好了,如下:

main.js

new Vue({
  router,
  store,
  render: h => h(App)
}).$mount('#app')

elive.js

new Vue({
  router,
  store,
  render: h => h(Elive)
}).$mount('#elive')

最后对多页的标题做添加
vue ui进行安装v-wechat-title依赖
配置代码如下

elive.js

Vue.use(require('vue-wechat-title'))


elive.vue

<!-- 一直播 -->
<template>
  <div id="elive" v-wechat-title="$route.meta.title">
    <router-view></router-view>
  </div>
</template>

<script>
export default {
  name: 'elive',
  data () {
    return {
    }
  },

  created () {
    // 获取手机dpr分辨率
    // let a = window.devicePixelRatio
    // console.log(a)
    let idealViewWidth = window.screen.width
    const BASICVALUE = 375
    document.documentElement.style.fontSize = (idealViewWidth / BASICVALUE) * 100 + 'px'
  },

  mounted () {},

  components: {},

  computed: {},

  methods: {}
}

</script>
<style lang='scss'>
html, body{
  margin: 0px;
  padding: 0px;
}
ul li, ol li, li{
  list-style: none;
}
p {
  display: block;
  margin-block-start: 0em;
  margin-block-end: 0em;
  margin-inline-start: 0px;
  margin-inline-end: 0px;
}
</style>

这样运行之后,想查看页面

npm run serve
进行访问
localhost:8080是访问的mobile下面的项目,

localhost:8080/elive.html#/是访问的elive下面的项目,

至此,多页面项目配置成功

不懂的,可以下面留言

持续更新~~~~

相关文章

  • vue多页应用

    vue如何将单页面改造成多页面应用 vue单页多页的开发环境配置+vue的开发思路

  • webpack4 构建vue多页工程

    webpack4 构建vue多页工程 多页应用开发环境配置 构建开发环境的配置,需要使用到webpack-dev-...

  • vue多页应用配置

    vue脚手架创建的项目都是单页面应用但是有一些场景下我们需要使用多页面应用(比如一个系统的后端和前端要分为不同的页...

  • 前端vue-cli4.0多页架构说明

    前端vue-cli4.0多页架构说明 [[toc]] 一、目录说明 二、骨架要点 1,mian.js配置 应用的主...

  • vue多页配置

    人生就像一列开往坟墓的列车,路途上会有很多站,很难有人至始至终陪你走完全程,当陪你的人要下车时,即便不舍,也要心存...

  • vue-router 配置路由

    vue-router 配置路由 用 Vue.js + vue-router 创建单页应用,是非常简单的。使用 Vu...

  • webpack

    webpack入门基本配置参考:https://www.webpackjs.com/guides/vue多页配置参...

  • Vue多页应用的极简配置

    Vue的官方脚手架工具 vue-cli 提供了很多种已配置好的模板,但这些模板的webpack配置看起来比较麻烦,...

  • 基于配置的vue多页应用开发

    vue是目前灰常火的前端框架,但是我们在开发pc的web端时经常需要用到多页系统,而不是简单的单页系统,而vue-...

  • webpack4构建多页应用,了解一下

    用webpack构建多页应用可以有2种思路,多页面单配置 vs. 多页面多配置。本例子采用多页面单配置,即在单页应...

网友评论

    本文标题:vue多页应用配置

    本文链接:https://www.haomeiwen.com/subject/ggmufctx.html