vue多页面入口配置

18 篇文章 0 订阅
15 篇文章 1 订阅

*index.html(主页\项目入口),app.vue(根组件),main.js(文件入口的配置)
1.进行项目入口的配置
在public下面,复制index.html修改文件名(里面内容可以不变)
在这里插入图片描述

<!DOCTYPE html>
<html lang="">
  <head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width,initial-scale=1.0">
    <link rel="icon" href="<%= BASE_URL %>favicon.ico">
    <title><%= htmlWebpackPlugin.options.title %></title>
  </head>
  <body>
    <noscript>
      <strong>We're sorry but <%= htmlWebpackPlugin.options.title %> doesn't work properly without JavaScript enabled. Please enable it to continue.</strong>
    </noscript>
    <div id="app"></div>
    <!-- built files will be auto injected -->
  </body>
</html>

2、进行跟组件和文件入口的配置
在这里插入图片描述
入口文件代码:
main.js:

import Vue from 'vue'
import App from './teacher.vue'
import router from './router'

Vue.config.productionTip = false

new Vue({
  router,
  // store,
  render: h => h(App)
}).$mount('#app')

根组件代码
teacher.vue:

<template>
  <div id="app">
      <!-- 这个是教师界面 -->
    <!-- <div id="nav"> -->
      <router-link to="/">Home</router-link> |
      <router-link to="/other">other</router-link>
    <router-view/> 
  </div>
</template>

<style lang="scss">
#app {
  font-family: Avenir, Helvetica, Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  text-align: center;
  color: #2c3e50;
}

#nav {
  padding: 30px;

  a {
    font-weight: bold;
    color: #2c3e50;

    &.router-link-exact-active {
      color: #42b983;
    }
  }
}
</style>

3.vue.config.js配置

let page = {
    index: {
        entry: 'src/pages/index/main.js',
        template: 'public/index.html',
        filename: 'index.html',
    },
    teacher: {
        entry: 'src/pages/teacher/main.js',
        template: 'public/teacher.html',
        filename: 'teacher.html',
    },
    student: {
        entry: 'src/pages/student/main.js',
        template: 'public/student.html',
        filename: 'student.html',
    }

}
module.exports = {
    pages: page
}

webpack配置项含义:
在这里插入图片描述
然后就是在各个单页面中进行开发了。。。

  • 1
    点赞
  • 12
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值