国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 網(wǎng)站 > 幫助中心 > 正文

vue-cli創(chuàng)建的項目,配置多頁面的實現(xiàn)方法

2024-07-09 22:41:03
字體:
供稿:網(wǎng)友

vue官方提供的命令行工具vue-cli,能夠快速搭建單頁應(yīng)用。默認(rèn)一個頁面入口index.html,那么,如果我們需要多頁面該如何配置,實際上也不復(fù)雜

假設(shè)要新建的頁面是rule,以下以rule為例

創(chuàng)建新的html頁面

<!DOCTYPE html><html>	<head>		<meta charset="utf-8">		<meta name="viewport" content="width=device-width,initial-scale=1.0">		<meta content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=no" name="viewport">		<meta http-equiv="pragma" content="no-cache">		<meta http-equiv="cache-control" content="no-cache">		<meta http-equiv="expires" content="0">		<title></title>	</head>	<body>		<span ><div ></div></span>		<!-- built files will be auto injected -->	</body></html>

創(chuàng)建入口文件Rule.vue和rule.js,仿照App.vue和main.js

<template>	<div >		<router-view></router-view>	</div></template><script>	export default {		name: 'lottery',		data() {			return {			}		},		mounted: function() {						this.$router.replace({					path:'/rule'			});		},	}</script><style lang="less">	body{		margin:0;		padding:0;	}</style>

rule.js

import Vue from 'vue'import Rule from './Rule.vue'import router from './router'import $ from 'jquery'//import vConsole from 'vconsole'import fastclick from 'fastclick'Vue.config.productionTip = falsefastclick.attach(document.body)Vue.config.productionTip = false; /* eslint-disable no-new */new Vue({ el: '#rule', router, template: '<Rule/>', components: { Rule },})

修改config/index.js

build添加rule地址,即編譯后生成的rule.html的地址和名字

build: {  // Template for index.html  index: path.resolve(__dirname, '../dist/index.php'),  rule: path.resolve(__dirname, '../dist/rule.php'),  …… }

rule: path.resolve(__dirname, '../dist/rule.php')表示編譯后再dist文件下,rule.html編譯后文件名為rule.php

修改build/webpack.base.conf.js

配置entry

entry: {  app: './src/main.js',    rule: './src/rule.js' },

修改build/webpack.dev.conf.js

在plugins增加

new HtmlWebpackPlugin({    filename: 'rule.html',    template: 'rule.html',    inject: true,    chunks:['rule']   }), 

修改build/webpack.prod.conf.js

在plugins增加

new HtmlWebpackPlugin({   filename: config.build.rule,   template: 'rule.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','rule']  }),
發(fā)表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發(fā)表
主站蜘蛛池模板: 石泉县| 金山区| 阿勒泰市| 蕲春县| 鲜城| 右玉县| 中西区| 自贡市| 县级市| 定兴县| 邹平县| 莱西市| 德清县| 远安县| 蓬安县| 鹤庆县| 凌云县| 赤壁市| 朝阳区| 洪江市| 寿宁县| 伊吾县| 北碚区| 堆龙德庆县| 荥经县| 绥阳县| 唐海县| 高密市| 福海县| 通河县| 平定县| 盘锦市| 宜兴市| 怀宁县| 蒙山县| 瑞安市| 乌鲁木齐县| 惠安县| 阜阳市| 巴彦县| 明星|