欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

vue webpack多頁面構(gòu)建的實(shí)例代碼

 更新時(shí)間:2018年09月11日 14:32:05   作者:ccyinghua  
這篇文章主要介紹了vue webpack多頁面構(gòu)建的實(shí)例代碼,代碼簡單易懂,非常不錯(cuò),具有一定的參考借鑒價(jià)值 ,需要的朋友可以參考下
, //模板路徑 inject: true, // excludeChunks 允許跳過某些chunks, 而chunks告訴插件要引用entry里面的哪幾個(gè)入口 // 如何更好的理解這塊呢?舉個(gè)例子:比如本demo中包含兩個(gè)模塊(index和about),最好的當(dāng)然是各個(gè)模塊引入自己所需的js, // 而不是每個(gè)頁面都引入所有的js,你可以把下面這個(gè)excludeChunks去掉,然后npm run build,然后看編譯出來的index.html和about.html就知道了 // filter:將數(shù)據(jù)過濾,然后返回符合要求的數(shù)據(jù),Object.keys是獲取JSON對象中的每個(gè)key excludeChunks: Object.keys(pages).filter(item => { return (item != page) }), 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' } // 需要生成幾個(gè)html文件,就配置幾個(gè)HtmlWebpackPlugin對象 module.exports.plugins.push(new HtmlWebpackPlugin(conf)) }

(5)修改config/index.js

'use strict'
// Template version: 1.3.1
// see http://vuejs-templates.github.io/webpack for documentation.
const path = require('path')
module.exports = {
 dev: {
 env: require('./dev.env'), // 引入當(dāng)前目錄下的dev.env.js,用來指明開發(fā)環(huán)境
 port: 3000, // dev-server的端口號(hào),可以自行更改
 autoOpenBrowser: true, // 是否自定代開瀏覽器
 // Paths
 assetsSubDirectory: 'static',
 assetsPublicPath: '/',
 // 下面是代理表,作用是用來,建一個(gè)虛擬api服務(wù)器用來代理本機(jī)的請求,只能用于開發(fā)模式
 proxyTable: {
  "/demo/api":"http://localhost:8080"
 },
 // Various Dev Server settings
 host: 'localhost', // can be overwritten by process.env.HOST
 autoOpenBrowser: false,
 errorOverlay: true,
 notifyOnErrors: true,
 poll: false, // https://webpack.js.org/configuration/dev-server/#devserver-watchoptions-
 /**
  * Source Maps
  */
 // https://webpack.js.org/configuration/devtool/#development
 devtool: 'cheap-module-eval-source-map',
 // If you have problems debugging vue-files in devtools,
 // set this to false - it *may* help
 // https://vue-loader.vuejs.org/en/options.html#cachebusting
 cacheBusting: true,
 // CSS Sourcemaps off by default because relative paths are "buggy"
 // with this option, according to the CSS-Loader README
 // (https://github.com/webpack/css-loader#sourcemaps)
 // In our experience, they generally work as expected,
 // just be aware of this issue when enabling this option.
 // 是否生成css,map文件,上面這段英文就是說使用這個(gè)cssmap可能存在問題,但是按照經(jīng)驗(yàn),問題不大,可以使用
 cssSourceMap: false
 },
 build: {
 env: require('./prod.env'), // 導(dǎo)入prod.env.js配置文件,只要用來指定當(dāng)前環(huán)境
 // Template for index.html
 index: path.resolve(__dirname, '../dist/index.html'), // 相對路徑的拼接
 // Paths
 assetsRoot: path.resolve(__dirname, '../dist'), // 靜態(tài)資源的根目錄 也就是dist目錄
 assetsSubDirectory: 'static', // 靜態(tài)資源根目錄的子目錄static,也就是dist目錄下面的static
 assetsPublicPath: '/', // 靜態(tài)資源的公開路徑,也就是真正的引用路徑
 /**
  * Source Maps
  */
 productionSourceMap: true, // 改成false運(yùn)行時(shí)不會(huì)出現(xiàn)map調(diào)試文件。;是否生成生產(chǎn)環(huán)境的sourcmap,sourcmap是用來debug編譯后文件的,通過映射到編譯前文件來實(shí)現(xiàn)
 // https://webpack.js.org/configuration/devtool/#production
 devtool: '#source-map',
 // Gzip off by default as many popular static hosts such as
 // Surge or Netlify already gzip all static assets for you.
 // Before setting to `true`, make sure to:
 // npm install --save-dev compression-webpack-plugin
 productionGzip: false, // 是否在生產(chǎn)環(huán)境中壓縮代碼,如果要壓縮必須安裝compression-webpack-plugin
 productionGzipExtensions: ['js', 'css'], // 定義要壓縮哪些類型的文件
 // Run the build command with an extra argument to
 // View the bundle analyzer report after build finishes:
 // `npm run build --report`
 // Set to `true` or `false` to always turn it on or off
 // 下面是用來開啟編譯完成后的報(bào)告,可以通過設(shè)置值為true和false來開啟或關(guān)閉
 // 下面的process.env.npm_config_report表示定義的一個(gè)npm_config_report環(huán)境變量,可以自行設(shè)置
 bundleAnalyzerReport: process.env.npm_config_report
 }
}

assetsRoot:執(zhí)行npm run build之后,項(xiàng)目生成的文件放到哪個(gè)目錄中。vue生成的文件都是靜態(tài)文件,可以放在nginx中,也可以放到Spring Boot項(xiàng)目的resources/static目錄中。
assetsPublicPath:項(xiàng)目的根路徑。注意,這個(gè)屬性在build、dev兩個(gè)環(huán)境都有,修改時(shí),應(yīng)該同時(shí)修改兩處。
port:這里改成3000,這個(gè)是在開發(fā)時(shí),webpack-dev-server運(yùn)行的端口。
proxyTable:這個(gè)屬性用于將請求轉(zhuǎn)發(fā)到指定地址去。這里的配置意思是將所有以/demo/api開頭的請求,都轉(zhuǎn)發(fā)到http://localhost:8080地址。

五、建立頁面

index/index.html

<!DOCTYPE html>
<html>
<head>
 <meta charset="utf-8">
 <title>index</title>
</head>
<body>
 <div id="app"></div>
</body>
</html>

index/index.js

import Vue from 'vue'
import IndexView from './index.vue'
import router from './router'
// import VueResource from 'vue-resource'; // 使用前先npm install vue-resource --save下載vue-resource
// Vue.use(VueResource);
new Vue({
 el: '#app',
 router,
 render: h => h(IndexView)
});

index/index.vue

<template>
 <div>
 <router-view></router-view>
 </div>
</template>

<script>
 export default {
 }
</script>

<style>
</style>

index/router/index.js

import Vue from 'vue'
import Router from 'vue-router'
import Hello from '../components/Hello.vue'
Vue.use(Router);
export default new Router({
 routes: [
 {
  path: '/',
  name: 'Hello',
  component: Hello
 }
 ]
})

index/components/Hello.vue

<template>
 <div>
 Hello {{ name }}
 </div>
</template>

<script>
 export default {
 data(){
  return {
  name: "admin"
  }
 },
 mounted(){
  //this.$http.get("/demo/api/userinfo").then(resp =>{
  // this.name = resp.data.data;
  //});
 }
 }
</script>
<style>
</style>

login/login.html

<!DOCTYPE html>
<html>
<head>
 <meta charset="utf-8">
 <title>login</title>
</head>
<body>
 <div id="app"></div>
</body>
</html>

login/login.js

import Vue from 'vue'
import LoginView from './login.vue'
// import VueResource from 'vue-resource';
// Vue.use(VueResource);
new Vue({
 el: '#app',
 render: h => h(LoginView)
})

login/login.vue

<template>
 <div>
 <form id="login-form">
  <label for="username">用戶名:</label>
  <input type="text" id="username" name="username">
  <br>
  <label for="password">密碼:</label>
  <input type="password" id="password" name="password"><br>
  <br>
  <button @click.prevent="submit">登錄</button>
 </form>
 </div>
</template>
<script>
 export default {
 methods:{
  submit(){
  window.location = "/demo/index.html";
  //let formData = new FormData(document.getElementById("login-form"));
  //this.$http.post("/demo/api/login", formData).then(resp => {
  // if (resp.data.status === 200){
  // window.location = "/index.html";
  // }else {
  // alert(resp.data.desc);
  // }
  //})
  }
 }
 }
</script>
<style>
</style>

六、運(yùn)行

http://localhost:3000/login.html

http://localhost:3000/index.html

總結(jié)

以上所述是小編給大家介紹的vue webpack多頁面構(gòu)建的實(shí)例代碼,希望對大家有所幫助,如果大家有任何疑問請給我留言,小編會(huì)及時(shí)回復(fù)大家的。在此也非常感謝大家對腳本之家網(wǎng)站的支持!

相關(guān)文章

  • Vue實(shí)現(xiàn)輪播圖組件的封裝

    Vue實(shí)現(xiàn)輪播圖組件的封裝

    Vue輪播圖組件的封裝可通過封裝組件、使用插件、配置化等方式實(shí)現(xiàn),主要包括圖片預(yù)加載、定時(shí)輪播、無限滾動(dòng)、手勢滑動(dòng)、響應(yīng)式布局等功能,實(shí)現(xiàn)方式可使用Vue的生命周期函數(shù)、自定義事件、計(jì)算屬性等技術(shù)
    2023-04-04
  • 淺談vue加載優(yōu)化策略

    淺談vue加載優(yōu)化策略

    這篇文章主要介紹了淺談vue加載優(yōu)化策略,小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,也給大家做個(gè)參考。一起跟隨小編過來看看吧
    2019-03-03
  • 關(guān)于Vue實(shí)現(xiàn)組件信息的緩存問題

    關(guān)于Vue實(shí)現(xiàn)組件信息的緩存問題

    這篇文章主要介紹了關(guān)于Vue實(shí)現(xiàn)組件信息的緩存問題的相關(guān)資料,需要的朋友可以參考下
    2017-08-08
  • 解決vue 使用axios.all()方法發(fā)起多個(gè)請求控制臺(tái)報(bào)錯(cuò)的問題

    解決vue 使用axios.all()方法發(fā)起多個(gè)請求控制臺(tái)報(bào)錯(cuò)的問題

    這篇文章主要介紹了解決vue 使用axios.all()方法發(fā)起多個(gè)請求控制臺(tái)報(bào)錯(cuò)的問題,具有很好的參考價(jià)值,希望對大家有所幫助。一起跟隨小編過來看看吧
    2020-11-11
  • vue中字符串如何拼接路由path路徑

    vue中字符串如何拼接路由path路徑

    這篇文章主要介紹了vue中字符串如何拼接路由path路徑方式,具有很好的參考價(jià)值,希望對大家有所幫助,如有錯(cuò)誤或未考慮完全的地方,望不吝賜教
    2023-12-12
  • vue中el-input綁定鍵盤按鍵(按鍵修飾符)

    vue中el-input綁定鍵盤按鍵(按鍵修飾符)

    這篇文章主要介紹了vue中el-input綁定鍵盤按鍵(按鍵修飾符),文中通過示例代碼介紹的非常詳細(xì),對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧
    2020-07-07
  • Vue?響應(yīng)式系統(tǒng)依賴收集過程原理解析

    Vue?響應(yīng)式系統(tǒng)依賴收集過程原理解析

    Vue 初始化時(shí)就會(huì)通過 Object.defineProperty 攔截屬性的 getter 和 setter ,為對象的每個(gè)值創(chuàng)建一個(gè) dep 并用 Dep.addSub() 來存儲(chǔ)該屬性值的 watcher 列表,這篇文章主要介紹了Vue?響應(yīng)式系統(tǒng)依賴收集過程分析,需要的朋友可以參考下
    2022-06-06
  • Vue如何使用混合Mixins和插件開發(fā)詳解

    Vue如何使用混合Mixins和插件開發(fā)詳解

    這篇文章主要介紹了Vue如何使用混合Mixins和插件開發(fā)詳解,文中通過示例代碼介紹的非常詳細(xì),對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧
    2020-02-02
  • vue+element-ui表格自定義列模版的實(shí)現(xiàn)

    vue+element-ui表格自定義列模版的實(shí)現(xiàn)

    本文主要介紹了vue+element-ui表格自定義列模版的實(shí)現(xiàn),通過插槽完美解決了element-ui表格自定義列模版的問題,具有一定的參考價(jià)值,感興趣的可以了解一下
    2024-05-05
  • vue中使用vue-router切換頁面時(shí)滾動(dòng)條自動(dòng)滾動(dòng)到頂部的方法

    vue中使用vue-router切換頁面時(shí)滾動(dòng)條自動(dòng)滾動(dòng)到頂部的方法

    這篇文章主要介紹了vue項(xiàng)目中在使用vue-router切換頁面的時(shí)候滾動(dòng)條自動(dòng)滾動(dòng)到頂部的實(shí)現(xiàn)方法,一般使用Window scrollTo() 方法實(shí)現(xiàn),本文給大家簡單介紹了crollTop的使用,需要的朋友可以參考下
    2017-11-11

最新評論