vue 2.0多页面开发
1、为项目添加多个入口
找到\build\webpack.base.conf.js文件:
module.exports = {
//...,
//vue的多页面开发:应用程序可以存在多个入口
entry: {
app: './src/main.js',
product: './src/product.js'
},
//...
}
2、为开发环境和生产环境配置入口对应的配置项
打开:\build\webpack.dev.conf.js
const devWebpackConfig = merge(baseWebpackConfig, {
//...
plugins: [
new webpack.DefinePlugin({
'process.env': require('../config/dev.env')
}),
new webpack.HotModuleReplacementPlugin(),
new webpack.NamedModulesPlugin(), // HMR shows correct file names in console on update.
new webpack.NoEmitOnErrorsPlugin(),
// https://github.com/ampedandwired/html-webpack-plugin
new HtmlWebpackPlugin({
filename: 'index.html',
template: 'index.html',
inject: true,
chunks:['app']
}),
new HtmlWebpackPlugin({
filename: 'product.html',
template: 'product.html',
inject: true,
chunks:['product']
}),
//...
]
})
打开:\build\webpack.prod.conf.js,plugins节点下面加:
//...
new HtmlWebpackPlugin({
filename: process.env.NODE_ENV === 'testing'
? 'index.html'
: config.build.index,
template: 'index.html',
inject: true,
minify: {
removeComments: true,
collapseWhitespace: true,
removeAttributeQuotes: true
// more options:
// https://github.com/kangax/html-minifier#options-quick-reference
},
// necessary to consistently work with multiple chunks via CommonsChunkPlugin
chunksSortMode: 'dependency',
chunks: ['manifest', 'vendor', 'app']
}),
new HtmlWebpackPlugin({
filename: process.env.NODE_ENV === 'testing'
? 'product.html'
: config.build.product,
template: 'product.html',
inject: true,
minify: {
removeComments: true,
collapseWhitespace: true,
removeAttributeQuotes: true
// more options:
// https://github.com/kangax/html-minifier#options-quick-reference
},
// necessary to consistently work with multiple chunks via CommonsChunkPlugin
chunksSortMode: 'dependency',
chunks: ['manifest', 'vendor', 'product']
}),
//...
3、配置编译环境
build: {
// Template for index.html
index: path.resolve(__dirname, '../dist/index.html'),
product: path.resolve(__dirname, '../dist/product.html'),
//...
}
4、根目录添加product.html
后面product关联的页面入口都是这个页面。
5、src目录添加product.js和product.vue
product.js类似于单页面的main.js的作用
import Vue from 'vue'
import product from './product.vue' Vue.config.productionTip = false /* eslint-disable no-new */
new Vue({
el: '#product',
render: h => h(product)
})
product.vue类似于单页面的App.vue的作用
<template>
<div id="prodcut">
{{msg}}
</div>
</template> <script>
export default {
name: 'prodcut',
data () {
return {
msg: 'I am prodcut'
}
}
}
</script>
6、添加测试链接
App.vue添加produt.html链接
<template>
<div id="app">
<img src="./assets/logo.png">
<a href="product.html">product</a><br>
<router-view/>
</div>
</template> <script>
export default {
name: 'App'
}
</script> <style>
#app {
font-family: 'Avenir', Helvetica, Arial, sans-serif;
-webkit-font-smoothing: antialiased;
-moz-osx-font-smoothing: grayscale;
text-align: center;
color: #2c3e50;
margin-top: 60px;
}
</style>
7、测试
可以看到编译后的文件index.html和product.html已经分别编译了,各自作为单页面的入口:

编译后的js也是各自的:

下面是演示效果:


8、源码
https://github.com/iprometheus/vue-multipage
9、参考文档
http://blog.csdn.net/Tank_in_the_street/article/details/73732801
vue 2.0多页面开发的更多相关文章
- vue.js2.0:如何搭建开发环境及构建项目
1,安装node.js Node.js官网:https://nodejs.org/en/ 进入Node.js官网,选择下载并安装Node.js.安装过程只需要点击“下一步”即可, 如下图,非常简单. ...
- 前端Vue项目——首页/课程页面开发及Axios请求
一.首页轮播图 1.elementUI走马灯 elementUI中 Carousel 走马灯,可以在有限空间内,循环播放同一类型的图片.文字等内容. 这里使用指示器样式,可以将指示器的显示位置设置在容 ...
- vue2.0多页面开发
我们平常用vue开发的时候总觉得vue好像就是专门为了单页面应用而诞生的,其实不是.因为vue在工程化开发的时候很依赖webpack,而webpack是将所有的资源整合到一块,弄成一个单页面.但是vu ...
- vue多页面与单页面开发的区别。
进入一家新的公司,要开发移动端app项目,前端技术选型时前端组长选的是vue的多页面开发,当时很蒙,vue不是单页面开发吗?咋出来多页面的.接触之后才发现确实存在也挺简单的,省去了路由表的配置.那就给 ...
- vue2.0与实战开发
慕课网实战 百度云 web前端实战: Node.js入门到企业Web开发中的应用 Web前端性能优化 让你的页面飞起来 前端跳槽面试必备技巧 前端JavaScript面试技巧全套 node.JS 线上 ...
- 【Alpaca】.Net版开源配置中心 - 技术选型 Vue 3.0
是否可以用 Vue 3.0 现有的Vue 2.* 不推荐,坐等Vue 3.0出迁移工具吧,手动改的话工作量还是不小的 新项目 考虑下团队内对Vue + TS + VS Code的熟练程度.过程中你会遇 ...
- vue搭建多页面开发环境
自从习惯开发了单页面应用,对多页面的页面间的相互跳转间没有过渡效果.难维护极度反感.但是最近公司技术老大说,当一个应用越来越大的时候单页面模式应付不来,但是没讲怎么应付不来,所以还得自己去复习一遍这两 ...
- 每天记录一点:NetCore获得配置文件 appsettings.json vue-router页面传值及接收值 详解webpack + vue + node 打造单页面(入门篇) 30分钟手把手教你学webpack实战 vue.js+webpack模块管理及组件开发
每天记录一点:NetCore获得配置文件 appsettings.json 用NetCore做项目如果用EF ORM在网上有很多的配置连接字符串,读取以及使用方法 由于很多朋友用的其他ORM如S ...
- vue-calendar 基于 vue 2.0 开发的轻量,高性能日历组件
vue-calendar-component 基于 vue 2.0 开发的轻量,高性能日历组件 占用内存小,性能好,样式好看,可扩展性强 原生 js 开发,没引入第三方库 Why Github 上很多 ...
随机推荐
- 微信小程序中如何获取for循环的item相关值到JS页面的问题
今天小程序开发过程中,遇到了这个棘手的问题.由于我没有前端基础,只是知道一点儿基本的HTML标签,所以卡了好久,特此分享,望后来的你,可以有所收获. measure step 1 *.WXML: ...
- Nginx 负载均衡4种模式
转载请标明出处:http://blog.csdn.net/zhaoyanjun6/article/details/80541464 本文出自[赵彦军的博客] 4 种负载均衡算法 upstream 支持 ...
- html常用标签学习笔记
本文内容: 前言:本文讲述的内容包括几类常用标签,以及这些标签的一些常用属性(有一些属性由于已经有CSS样式来代替,所以对于一些不重要的这里选择不讲) 排版标签 段落标签:p div span 标题标 ...
- mysql之系统默认数据库
相关内容: 系统默认数据库information_schema,performance_schema,mysql,test 的意义 首发时间:2018-02-23 17:10 安装mysql完成后, ...
- spark查看DF的partition数目及每个partition中的数据量【集群模式】
println("--------------------"+data.rdd.getNumPartitions) // 获取DF中partition的数目 val partiti ...
- mssql sqlserver for xml EXPLICIT 用法详解说明
摘要:下文通过举例的方式,详细说明"for xml EXPLICIT"关键字的用法,如下所示:实验环境:sql server 2008 R2 EXPLICIT的功能:将数据表采用特 ...
- python3 requests + BeautifulSoup 爬取阳光网投诉贴详情实例代码
用到了requests.BeautifulSoup.urllib等,具体代码如下. # -*- coding: utf-8 -*- """ Created on Sat ...
- SQL Server数据类型int、bigint、smallint、tinyint对比表
SQL Server数据类型int.bigint.smallint.tinyint对比表 数据类型 范围 存储 bigint -2^63 (-9,223,372,036,854,775,808) 到 ...
- php判断手机是安卓系统还是ios系统
最近项目,要判断用户的手机是安卓的还是ios的,搜了一下相关的资料,最终获得的结果.事实证明,是有效的!主要是要用到HTTP_USER_AGENT,它表示的意思是用来检查浏览页面的访问者在用什么操作系 ...
- Unity 琐碎(2): Shader 颜色调试
Shader的调试有点蛋疼,最近在测试Image Effect中深度还原时,不知道输出的结论是否正确,后面就采取了这种策略.在物体上世界坐标位转换区间到[0,1],然后作为颜色进行输出.然后Image ...