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 ...
随机推荐
- Photon Server 实现注册与登录(五) --- 服务端、客户端完整代码
客户端代码:https://github.com/fotocj007/PhotonDemo_Client 服务端代码:https://github.com/fotocj007/PhotonDemo_s ...
- python pyyaml 使用教程(代码案例)
test.py 内容 # 运行前,请先安装pyyaml模块 # pip3 install -i https://pypi.douban.com/simple/ pyyaml==5.1.1 import ...
- MySQL_Utilities工具
需求 Python 2.6 MySQL Connector/Python 连接器 下载地址: http://dev.mysql.com/downloads/utilities/ ...
- github骚操作
限制搜索 in关键词限制搜索范围 命令 说明 xxx in:name 项目名包含xxx的 xxx in:description 项目描述包含xxx的 xxx in:readme 项目的readme文件 ...
- jquery model 框设定
https://www.bootcdn.cn/ 国内网址引用 js function searchItemInfo(conditionNo,lotCD,itemKey) { var conditi ...
- 使用cublas 矩阵库函数实现矩阵相乘
2014-08-10 cublas中执行矩阵乘法运算的函数 首先要注意的是cublas使用的是以列为主的存储方式,和c/c++中的以行为主的方式是不一样的.处理方法可参考下面的注释代码 // SOME ...
- ORACLE和SQL查询库数据量
ORACLE根据账号查询每张表数据量: select t.table_name,t.num_rows from user_tables t ORDER BY NUM_ROWS DESC; SQL SE ...
- interrupt分析
转载自 https://blog.csdn.net/zhangliangzi/article/details/52485319 interrupt简述 interrupt() 方法只是改变中断状态而已 ...
- ssh: Bad configuration option: usedns
某天突然听到同事说服务器上git用不了了,上去一看,确实用不了了,git pull报出了如下错误: $ git pull /etc/: Bad configuration option: usedns ...
- python多继承下的查找顺序-MRO原则演变与C3算法
在python历史版本中的演变史 python2.2之前: MRO原则: 只有经典类,遵循深度优先(从左到右)原则, 存在的问题:在有重叠的多继承中,违背重写可用原则 解决办法是再设计类的时候不要设计 ...