vue-cli如何創(chuàng)建的項(xiàng)目配置多頁(yè)面

這篇文章主要介紹vue-cli如何創(chuàng)建的項(xiàng)目配置多頁(yè)面,文中介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們一定要看完!

十多年的新豐網(wǎng)站建設(shè)經(jīng)驗(yàn),針對(duì)設(shè)計(jì)、前端、開(kāi)發(fā)、售后、文案、推廣等六對(duì)一服務(wù),響應(yīng)快,48小時(shí)及時(shí)工作處理。成都全網(wǎng)營(yíng)銷推廣的優(yōu)勢(shì)是能夠根據(jù)用戶設(shè)備顯示端的尺寸不同,自動(dòng)調(diào)整新豐建站的顯示方式,使網(wǎng)站能夠適用不同顯示終端,在瀏覽器中調(diào)整網(wǎng)站的寬度,無(wú)論在任何一種瀏覽器上瀏覽網(wǎng)站,都能展現(xiàn)優(yōu)雅布局與設(shè)計(jì),從而大程度地提升瀏覽體驗(yàn)。創(chuàng)新互聯(lián)從事“新豐網(wǎng)站設(shè)計(jì)”,“新豐網(wǎng)站推廣”以來(lái),每個(gè)客戶項(xiàng)目都認(rèn)真落實(shí)執(zhí)行。

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

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

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

<!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 id="rule"></div></span>
		<!-- built files will be auto injected -->
	</body>
</html>

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

<template>
	<div id="rule">
		<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 = false
fastclick.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']
  }),

以上全部

當(dāng)后臺(tái)地址跳轉(zhuǎn)到你的新建的頁(yè)面后,由于現(xiàn)在配置的默認(rèn)路由是公用的,可自己配置多個(gè)路由文件,分別引用。

可在Rule.vue中路由跳轉(zhuǎn)到指定路由,以實(shí)現(xiàn)頁(yè)面控制

mounted: function() {
			
	this.$router.replace({
		path:'/rule'
	});
},

以上是“vue-cli如何創(chuàng)建的項(xiàng)目配置多頁(yè)面”這篇文章的所有內(nèi)容,感謝各位的閱讀!希望分享的內(nèi)容對(duì)大家有幫助,更多相關(guān)知識(shí),歡迎關(guān)注創(chuàng)新互聯(lián)行業(yè)資訊頻道!

網(wǎng)頁(yè)標(biāo)題:vue-cli如何創(chuàng)建的項(xiàng)目配置多頁(yè)面
URL分享:http://muchs.cn/article30/gedeso.html

成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供外貿(mào)網(wǎng)站建設(shè)、定制網(wǎng)站、網(wǎng)站設(shè)計(jì)、商城網(wǎng)站、建站公司、企業(yè)建站

廣告

聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請(qǐng)盡快告知,我們將會(huì)在第一時(shí)間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如需處理請(qǐng)聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時(shí)需注明來(lái)源: 創(chuàng)新互聯(lián)

成都app開(kāi)發(fā)公司