1.0版本点这里 -> 博客:vue-cli3构建多页面应用1.0   github:vue-cli-multipage

在1.0版本上做了以下改进:

1. 增加pages.config.js,入口js、模版html、访问路径、页面标题全部都可以配置,如果访问路径配置成多级,也会自动打包成多级目录

module.exports = {
page1: {
entry: './src/pages/page1/index.js', // 入口js
template: 'index.html', // 模版文件 默认是public里的index.html
filename: 'page1.html', // url访问路径
title: 'title-page1', // 页面标题
},
page2: {
entry: './src/pages/page2/index.js',
template: 'index.html',
filename: 'page2.html',
title: 'title-page2',
},
page2_1: {
entry: './src/pages/page2/page2_1/index.js',
template: 'index.html',
path: '/page2',
filename: 'page2/1.html',
title: 'title-page2-1'
}
}

2. vue.config.js中配置 生产环境下打包去掉console.log,静态文件打包后放在static文件夹下

const pages = require('./pages.config')

module.exports = {
pages,
configureWebpack: (config) => {
// 生产环境下去掉console.log
if (process.env.NODE_ENV === 'production') {
config.optimization.minimizer[0].options.terserOptions.compress.drop_console = true
}
},
lintOnSave: false,
assetsDir: 'static', // 打包后静态文件夹名称
chainWebpack: config => {
// 修复热更新
config.resolve.symlinks(true);
},
devServer: {
open: true, // npm run serve 自动打开浏览器
index: '/page1.html' // 默认启动页面
}
}

3. 增加全局插件:toast和loading

 请求触发时自动showloading,请求成功后hideloading。多个请求时等所有请求完成后hideloading

如果请求报错,自动弹出toast显示报错内容

import axios from 'axios'
import Vue from 'vue';
import {toast, loading} from '@/plugins' Vue.config.productionTip = false
Vue.config.devtools = process.env.NODE_ENV !== 'production'; Vue.use(toast)
Vue.use(loading) let vm = new Vue() axios.defaults.withCredentials = true
let http = axios.create({
baseURL: process.env.VUE_APP_API,
timeout: 60 * 1000
}) // 获取CancelToken 有需要的话可以用source.cancel();取消其他请求
const CancelToken = axios.CancelToken, source = CancelToken.source();
let queueNum = 0 http.interceptors.request.use(
(config) => {
// 请求前显示全局loading
queueNum += 1
vm.$loading.show()
// 全局添加cancelToken
config.cancelToken = source.token;
return config;
},
(err) => {
const error = err;
return Promise.reject(error);
},
) http.interceptors.response.use(
response => {
// 全部请求完成后hide loading
queueNum -= 1
if (queueNum === 0) {
vm.$loading.hide()
}
const res = response.data if (res.errorCode != 0) {
vm.$toast({text: `${res.errorMsg}(${res.errorCode})`})
return Promise.reject(response)
} else{
return res
}
},
error => {
if (error && error.response) {
queueNum -= 1
if (queueNum === 0) {
vm.$loading.hide()
}
const res = error.response.data
vm.$toast({text: `${res.errorMsg}(${res.errorCode})`})
} else {
vm.$loading.hide()
vm.$toast({text: error})
}
return Promise.reject(error)
}
) export function GET(url, paramsOrData) {
return http({ method: 'GET', url, params: paramsOrData })
} export function POST(url, paramsOrData) {
return http({ method: 'POST', url, data: paramsOrData })
} export default http

4. 公共代码的提取:引用http.js的页面在非生产环境下都会开启devtools,方便联调

5. public/index.html

 设置apple-touch-icon是为了避免在safari浏览器报apple-touch-icon.png 404,safari浏览器可以将页面添加到桌面,如果不设置apple-touch-icon,图标默认是页面的截图

<!-- 禁止缓存html -->
<meta http-equiv="pragma" content="no-cache">
<!-- safari浏览器添加到桌面的图标 -->
<link rel="apple-touch-icon" href="./favicon.ico"/>

2.0版本 github vue-cli-multipage2

帮助到你的话请给个小星星哦

vue-cli3构建多页面应用2.0的更多相关文章

  1. 借助 Vue 来构建单页面应用

    原文: https://github.com/MeCKodo/vue-tutorial 主题 Vue.js (1/2)Vue构建单页应用最佳实战 前言 我们将会选择使用一些vue周边的库 1.使用no ...

  2. 使用Vue CLI3开发多页面应用

    一.安装vue-cli3 1.如果你已经全局安装了旧版本的 vue-cli(1.x 或 2.x),你需要先通过 npm uninstall vue-cli -g 或 yarn global remov ...

  3. spring boot使用vue+vue-router构建单页面应用

    spring boot http://docs.spring.io/spring-boot/docs/current-SNAPSHOT/reference/htmlsingle/ vue https: ...

  4. Vue项目构建开发笔记(vue-lic3.0构建的)

    1.router.js里面 { path: '/about', name: 'about', // route level code-splitting // this generates a sep ...

  5. 使用vue-cli构建多页面应用+vux(一)

    众所皆知,vue对于构建单页面应该相当方便,但是在项目中难免遇到有多个页面的情况. 1.先安装vue-cli脚手架,具体步骤看vue-cli的官方github地址 https://github.com ...

  6. 【vue】使用vue构建多页面应用

    先了解一些单页面和多页面的区别 mm 多页应用模式MPA 单页应用模式SPA 应用构成 由多个完整页面构成 一个外壳页面和多个页面片段构成 跳转方式 页面之间的跳转是从一个页面跳转到另一个页面 页面片 ...

  7. vue cli3.0 结合echarts3.0和地图的使用方法

    echarts 提供了直观,交互丰富,可高度个性化定制的数据可视化图表.而vue更合适操纵数据. 最近一直忙着搬家,就没有更新博客,今天抽出空来写一篇关于vue和echarts的博客.下面是结合地图的 ...

  8. vue cli3超详细创建多页面配置

    1.首先按照vue cli3 给的入门文档下载个vue cli3 如果之前下载了vue cli2的要先卸载之前的 2.检查安装是否成功 3.ok,现在环境搭建好了,新建项目 vue create he ...

  9. 解决vue/cli3.0 语法验证规则 ESLint: Expected indentation of 2 spaces but found 4. (indent)

    当你使用vue/cli3.0的时,有可能出现雁阵规则 ESLint: Expected indentation of 2 spaces but found 4. (indent) 解决方法 1.在vu ...

随机推荐

  1. thinkphp5日志文件权限的问题

    由于www用户和root用户(比如command的cli进程日志)都有可能对log文件进行读写. 如果是由www用户创建的log文件,不会出任何问题. 但是如果是先由root用户创建的log文件,然后 ...

  2. selenium登录实验楼

    from selenium import webdriver from selenium.webdriver.common.by import By from selenium.webdriver.s ...

  3. zookeeper集群搭建与升级

    zookeeper 1.zookeeper功能 1-1.配置管理 集中管理配置文件实现服务治理 1-2.命名服务 如为了通过网络访问一个系统,我们得知道对方的IP地址,但是IP地址对人非常不友好,这个 ...

  4. 第九章 ZYNQ-MIZ701 片上ADC的使用

      9.0难度系数★☆☆☆☆☆☆ 9.1实验概述 这次借助zynq的内嵌的XADC来采集zynq内部的一些参数: •VCCINT:内部PL核心电压 •VCCAUX:辅助PL电压 •VREFP:XADC ...

  5. 怎样通过html标签名获取元素节点集合

    方法1. 使用document.querySelectorAll(); 方法2. 使用document.getElementsByTagName(); document.querySelectorAl ...

  6. Redis 的订阅发布(PUB/SUB)示例

    ConnectionMultiplexer redis = ConnectionMultiplexer.Connect("127.0.0.1"); ISubscriber sub ...

  7. js将阿拉伯数字转换成汉字大写

    适用场景:票据,结算凭证等.将任意数字的金额,转换成汉字大写的形式.例如:1234.50 -> 壹仟贰佰叁拾肆圆伍角.壹.贰.叁.肆 直接贴代码,如下: //阿拉伯数字转换成大写汉字 funct ...

  8. Git详细操作

    Git详细操作 一.本地配置 1公钥钥配置 1.参考帮助文档:https://gitee.com/help/ 仓库管理 =公钥管理 =生成/添加SSH公钥 ssh-keygen -t rsa -C & ...

  9. 【异常】hbase启动后hdfs文件权限目录不一致,导致Phoenix无法删除表结构

    1 异常信息 Received error when attempting to archive files ([class org.apache.hadoop.hbase.backup.HFileA ...

  10. Matlab修改数值格式/精度/小数位数

    ————————————命令行方法————————————— 直接在命令行中输入以下命令,但该命令不影响数据的存储形式和计算精度,下次还需进行修改. format 默认格式  format short ...