vue-cli3构建多页面应用2.0
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的更多相关文章
- 借助 Vue 来构建单页面应用
原文: https://github.com/MeCKodo/vue-tutorial 主题 Vue.js (1/2)Vue构建单页应用最佳实战 前言 我们将会选择使用一些vue周边的库 1.使用no ...
- 使用Vue CLI3开发多页面应用
一.安装vue-cli3 1.如果你已经全局安装了旧版本的 vue-cli(1.x 或 2.x),你需要先通过 npm uninstall vue-cli -g 或 yarn global remov ...
- spring boot使用vue+vue-router构建单页面应用
spring boot http://docs.spring.io/spring-boot/docs/current-SNAPSHOT/reference/htmlsingle/ vue https: ...
- Vue项目构建开发笔记(vue-lic3.0构建的)
1.router.js里面 { path: '/about', name: 'about', // route level code-splitting // this generates a sep ...
- 使用vue-cli构建多页面应用+vux(一)
众所皆知,vue对于构建单页面应该相当方便,但是在项目中难免遇到有多个页面的情况. 1.先安装vue-cli脚手架,具体步骤看vue-cli的官方github地址 https://github.com ...
- 【vue】使用vue构建多页面应用
先了解一些单页面和多页面的区别 mm 多页应用模式MPA 单页应用模式SPA 应用构成 由多个完整页面构成 一个外壳页面和多个页面片段构成 跳转方式 页面之间的跳转是从一个页面跳转到另一个页面 页面片 ...
- vue cli3.0 结合echarts3.0和地图的使用方法
echarts 提供了直观,交互丰富,可高度个性化定制的数据可视化图表.而vue更合适操纵数据. 最近一直忙着搬家,就没有更新博客,今天抽出空来写一篇关于vue和echarts的博客.下面是结合地图的 ...
- vue cli3超详细创建多页面配置
1.首先按照vue cli3 给的入门文档下载个vue cli3 如果之前下载了vue cli2的要先卸载之前的 2.检查安装是否成功 3.ok,现在环境搭建好了,新建项目 vue create he ...
- 解决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 ...
随机推荐
- pt-table-checksum和pt-table-sync使用
pt-table-checksum和pt-table-sync使用 数据库版本:5.6.25 pt工具版本:2.2.14 主从关系一:不同机器同一端口 10.10.228.163:4306(rescs ...
- S03_CH03_AXI_DMA_OV7725摄像头采集系统
S03_CH03_AXI_DMA_OV7725摄像头采集系统 3.1概述 本课程讲解如何搭建基于DMA的图形系统,方案原理如下. 摄像头采样图像数据后通过DMA送入到DDR,在PS部分产生DMA接收中 ...
- shell习题第14题:
[题目要求] 需求,根据web服务器的访问日志,把一些请求高的ip给拒绝掉,并且每隔半小时把不再发起请求或者请求量很小的ip给解封 假设: 1. 一分钟内请求量高于100次的ip视为不正常的请求 2. ...
- Java String类源码
String类的签名(JDK 8): public final class String implements java.io.Serializable, Comparable<String&g ...
- CCF - CCSP 2018-01 绝地求生 BFS
BFS从安全地区方向搞一下就好了 1.还是注意每回合清空 2.posx居然开小了,可不能犯这种错误 3.地图用a和节点的dis重名了,建议其他变量禁止用a命名 4.在输入数据之前continue了,这 ...
- ORM框架之EntityFramework介绍
ORM框架之EntityFramework介绍 1. 简介 大家好!我是高堂. 作为一位伪前端程序猿,我给大家介绍一下微软的自家的 ORM框架. ADO.NET Entity Framework 以下 ...
- 关于如何查看 MySQL 信息、查看Oracle 版本
方法一: 进入mysql cmd, mysql -u root status; 将显示当前mysql的version的各种信息. 方法二: 还是在mysql的cmd下,输入: select versi ...
- SpringBoot整合Mybatis问题
IDEA对xml文件处理的方式不同 在Eclipse中到dao文件与mapper.xml文件只要在同一级目录下即可 在IDEA中mapper.xml要放在resources目录下 注:resource ...
- 如何确定asp.net请求生命周期的当前处理事件
1 首先在全局应用程序里面添加如下代码 using System; using System.Collections.Generic; using System.Linq; using System. ...
- Java安全停止线程方法
1. 早期Java提供java.lang.Thread类型包含了一些列的方法 start(), stop(), stop(Throwable) and suspend(), destroy() and ...