适合场景

多页面多系统应用

所有系统都在同一目录下。配置多入口多出口。每个系统之间可以链接。每个系统内依然采用Vue单页应用开发。
产品需求:一套代码 兼容pc端和移动端 , 移动端和pc端的样式布局差别很大,需要使用多界面,并判断使用手机的时候跳转移动端代码,使用pc端跳转pc端代码。

项目目录

分为两部分代码,pc 和mobile

第一步:创建一个登陆页面的文件

在项目public文件夹下创建一个login.html,其实就是将index.html复制一份,将title改一下:

<!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"><title>Document</title>
</head><body><div id="login"></div></body></html>

第二步:在src文件夹下创建一个modules文件夹,分别创建login.main.js、login.router.js、login.vue三个文件

三个文件内容如下:

login.main.js: 仿照main.js

import Vue from 'vue'
import App from './login.vue'
import router from './login.router'Vue.config.productionTip = falsenew Vue({router,render: h => h(App)
}).$mount('#login')

login.router.js (仿照router.js)

router/index.js中需要的设置

import Vue from 'vue'
import VueRouter from 'vue-router'
Vue.use(VueRouter)
// 首页用重定向的方式来进行适配的方案:
const redirectPath = /Android |webos | iphone iPod BlackBerry liPad/i.test(navigator.userAgent) ? '/m_index' : '/index';import index from '../../components/index.vue'
Vue.use(VueRouter)const routes = [{path: "/",redirect: redirectPath,},{path: '/index',name: index,component: index},]
const router = new VueRouter({// 去掉路由中的#号mode: 'history',routes
})
router.beforeEach((to, from, next) => {if (/Android|webOS|iPhone|iPod|BlackBerry/i.test(navigator.userAgent)) {window.location.href = '/m_index.html/'return}next()
})
export default router

login.router.js

import Vue from 'vue'
import VueRouter from 'vue-router'
import login from '../../components/login.vue'
Vue.use(VueRouter)const routes = [{path: '/login',name: login,component: login},]const router = new VueRouter({mode: 'history',base: process.env.BASE_URL,routes
})export default router

界面自行配置

vue.config.js

const path = require('path')
const debug = process.env.NODE_ENV !== 'production'
module.exports = {publicPath: '/', // 根域上下文目录outputDir: 'dist', // 构建输出目录assetsDir: 'static', // 静态资源目录 (js, css, img, fonts)lintOnSave: false, // 是否开启eslint保存检测,有效值:ture | false | 'error'runtimeCompiler: true, // 运行时版本是否需要编译transpileDependencies: [], // 默认babel-loader忽略mode_modules,这里可增加例外的依赖包名productionSourceMap: true, // 是否在构建生产包时生成 sourceMap 文件,false将提高构建速度configureWebpack: config => { // webpack配置,值位对象时会合并配置,为方法时会改写配置if (debug) { // 开发环境配置config.devtool = 'cheap-module-eval-source-map'} else { // 生产环境配置}Object.assign(config, { // 开发生产共同配置resolve: {// 起别名alias: {'@': path.resolve(__dirname, './src'),'@c': path.resolve(__dirname, './src/components'),'vue$': 'vue/dist/vue.esm.js','assets': '@/assets','common': '@/common','components': '@/components','network': '@/network','router': '@router','views': '@views',}},})},// css: {//   loaderOptions: {//     css: {},//     postcss: {//       plugins: [//         require('postcss-px2rem')({//           remUnit: 37.5//         })//       ]//     }//   }// },pages: {//(1)输出一个页面//  main: {//    entry: 'src/main.js',//    template: 'public/index.html',//    filename: 'maker.html',//    chunks: ['chunk-vendors', 'chunk-common', 'index']//  },//(2)输出多个页面login: {template: "public/login.html",entry: "src/modules/mobile/login.main.js",filename: "login.html",title: "login",keywords: "333",description: "444",},index: {template: "public/index.html",entry: "src/modules/pc/main.js",filename: "index.html",title: "index",keywords: "333",description: "444",}},chainWebpack: config => { // webpack链接API,用于生成和修改webapck配置,https://github.com/vuejs/vue-cli/blob/dev/docs/webpack.md// 这里是对环境的配置,不同环境对应不同的BASE_URL,以便axios的请求地址不同config.plugin('define').tap(args => {args[0]['process.env'].BASE_URL = JSON.stringify(process.env.BASE_URL)return args})if (debug) {// 本地开发配置} else {// 生产开发配置}},parallel: require('os').cpus().length > 1, // 构建时开启多进程处理babel编译pluginOptions: { // 第三方插件配置},pwa: {},devServer: {open: false,host: 'localhost',port: 80,https: false,hotOnly: false,// 注意下面 需要写入接口 , 如果没有接口则进行注释即可proxy: { // 配置跨域'/api': {target: 'https://127.0.0.1:80', //接口域名ws: true, //是否代理websocketschangOrigin: true,  //是否跨域pathRewrite: {        //重置路径'^/api': ''}}},}
}

即可完成

vuecli3 实现 移动端和pc端 界面切换(两套代码)相关推荐

  1. 移动端和PC端的pdf预览与下载

    34.移动端和PC端的pdf的预览与下载 1.预览 需求:在手机端实现pdf的文件与下载,主要是zlb_app中 实现过程:在研究了vue-pdf.pdfjs.pdfh5之后,选择了vue-pdf-s ...

  2. Vue 移动端、PC 端适配

    Vue 移动端.PC 端适配可以使用 lib-flexible.amfe-flexible.postcss-pxtorem.postcss-px2rem 和 postcss-px-to-viewpor ...

  3. 移动端和PC端的录屏软件汇总,需要的朋友速看

    有朋友有屏幕录制的需求吗?我在这里汇总了移动端和PC端的录屏软件,有需要的朋友就看看吧. 移动端录屏软件: 1.嘿录录屏 它是一款全新的手机录屏软件,支持录制游戏.直播.课程.会议.网课等内容.操作简 ...

  4. js判断移动端,pc端,安卓,苹果浏览器的方法

    js 判断安卓或者ios 之indexOf方式(一) //判断访问终端 var browser={versions:function(){var u = navigator.userAgent, ap ...

  5. 360浏览器打不开网页_苹果移动端、PC端safari浏览器打不开网页的解决方案!

    你还在为苹果自带的safari浏览器打不开网页而苦恼吗,接下来的答案会帮助你解决苦恼. 苹果自带safari浏览器的设备分为两种:移动端.PC端.因此不同设备出现safari浏览器打不开网页的情况需要 ...

  6. js 判断移动端还是pc端,ios或者android

    js 判断移动端还是pc端,ios或者android 法一: function IsPC(){ var userAgentInfo = navigator.userAgent;var Agents = ...

  7. vue 判断移动端、pc端

    判断移动端或pc端 经常在项目中会有支持 pc 与手机端需求.并且pc与手机端是两个不一样的页面.这时就要求判断设置,根据不同的设置跳转不同的路由. 先写个方法: //APP.vue isMobile ...

  8. 移动端和PC端弹出遮罩层后,页面禁止滚动的解决方法及探究

    移动端和PC端弹出遮罩层后,页面禁止滚动的解决方法及探究 参考文章: (1)移动端和PC端弹出遮罩层后,页面禁止滚动的解决方法及探究 (2)https://www.cnblogs.com/ranyon ...

  9. C#和JQ判断移动端还是PC端

    判断移动端还是PC端浏览网页可以使用两种方法: 1.在C#语句进行判断 /// <summary>/// 判断是移动端/// </summary>/// <returns ...

最新文章

  1. 一加3t刷机后还卡_OPPO A5?A7?A57?刷机注意:这几款手机千万别混淆!
  2. Windows10——荣耀笔记本任务栏图标显示异常且无显示/隐藏图标的箭头解决方案
  3. express接受get数据
  4. 最新PC游戏下载链接
  5. 华为switch上配置MSTP
  6. 华为机试HJ3:明明的随机数
  7. 免费python网络课程-2019年10种免费的Python学习课程
  8. Mysql的安全设置
  9. Direct3d基础一__CPP基础之碰到无法打开源文件D3DX11.h如何解决
  10. Vue packages version mismatch解决方案
  11. 写作能赚钱吗?不,写作的首要目的,是认识自己
  12. 《MFQPPDCS》学习心得--TE---测试广度和深度
  13. 浅谈微信小程序对于创业者,意味着什么?
  14. 《挑战程序设计竞赛》--初级篇习题POJ部分【动态规划】
  15. 如何适配处理iphoneX底部的横条 - ios
  16. vuex存储什么数据_【存储知识小讲堂系列】为什么数据隔离很重要_热点新闻-新闻频道-中文科技资讯...
  17. 计算机毕业设计ssm创梦宝大学生创业众筹平台cds88系统+程序+源码+lw+远程部署
  18. 用友ERP系统排名?用友ERP办公系统怎么选?什么是用户口碑最好的用友ERP系统?
  19. webshell 提权
  20. 晒晒我这两年的私活单,业余时间月入6k,有份副业也太香啦

热门文章

  1. 中基鸿业投资理财你需要知道的五件事
  2. win32学习笔记(八) 图标资源、光标资源、字符串资源、加速键资源
  3. 上班时觉得无聊,任务做完了你应该怎么利用这段时间呢
  4. 16、控件使用之图标动画显示和图片动画显示
  5. Ubuntu下 火狐的中文版本
  6. 大富豪5.2 ,棋牌数据库记录
  7. error: ‘PoseStamped’ in namespace ‘geometry_msgs’ does not name a type
  8. Leica TPS基础知识
  9. Mysql如何查找my.ini文件
  10. 微信小程序实现对图片的缩放与裁剪