Compare commits

...

2 Commits

Author SHA1 Message Date
燕鹏 1541e215ba 提取router 3 years ago
燕鹏 616602928a 修改配置 3 years ago
  1. BIN
      public/favicon.ico
  2. 20
      public/index.html
  3. 62
      src/app/App.vue
  4. 28
      src/app/main.js
  5. 1
      src/index/App.vue
  6. 2
      src/index/main.js
  7. 21
      src/index/router.js
  8. 26
      src/router/index.js
  9. 29
      src/subpage/App.vue
  10. 12
      src/subpage/main.js
  11. 21
      src/subpage/router.js
  12. 5
      src/subpage/views/About.vue
  13. 21
      src/subpage/views/Home.vue
  14. 0
      src/views/About.vue
  15. 0
      src/views/Home.vue
  16. 6
      vue.config.js

BIN
public/favicon.ico

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.1 KiB

20
public/index.html

@ -0,0 +1,20 @@
<!DOCTYPE html>
<html>
<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>首页</title>
</head>
<body>
<noscript>
<strong>We're sorry but multipage 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>

62
src/app/App.vue

@ -0,0 +1,62 @@
<template>
<div id="app">
<div id="nav">
<p>我是app页面,当前appId {{ appId }}</p>
<router-link to="/">Home</router-link>
<router-link to="/about">About</router-link>
</div>
<router-view/>
</div>
</template>
<script>
import HelloWorld from "@/components/HelloWorld";
export default {
name: 'home',
components: {
HelloWorld
},
data() {
return {
appId: ''
}
},
mounted() {
if (this.$route.query.appId) {
this.appId = this.$route.query.appId
}
let search = window.location.search
if (search.indexOf('appId') !== -1) {
if (search.indexOf('&') === -1) {
this.appId = search.substring(7)
} else {
let str = search.substring(7)
this.appId = str.substring(0, str.indexOf('&'))
}
}
console.log(`这个是默认页面的主页:${this.$store.state.myname}`)
}
}
</script>
<style lang="less">
#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>

28
src/app/main.js

@ -0,0 +1,28 @@
import Vue from 'vue'
import App from './App.vue'
import router from '@/router'
import store from '@/store'
Vue.config.productionTip = false
router.beforeEach((to, from, next) => {
if (!to.query.appId) {
if (from.query.appId) {
to.query.appId = from.query.appId
} else {
to.query.appId = window.location.href.match(/appId=(.*)/)[1]
}
}
next()
})
router.afterEach((to, from) => {
})
new Vue({
router,
store,
render: h => h(App)
}).$mount('#app')

1
src/index/App.vue

@ -1,6 +1,7 @@
<template>
<div id="app">
<div id="nav">
<p>我是默认页面 <a href="app.html?appId=asdfghjkl" target="_blank">跳轉到APP</a></p>
<router-link to="/">Home</router-link> |
<router-link to="/about">About</router-link>
</div>

2
src/index/main.js

@ -1,6 +1,6 @@
import Vue from 'vue'
import App from './App.vue'
import router from './router'
import router from '@/router/'
import store from '@/store'
Vue.config.productionTip = false

21
src/index/router.js

@ -1,21 +0,0 @@
import Vue from 'vue'
import Router from 'vue-router'
import Home from './views/Home.vue'
import About from './views/About.vue'
Vue.use(Router)
export default new Router({
routes: [
{
path: '/',
name: 'home',
component: Home
},
{
path: '/about',
name: 'about',
component: About
}
]
})

26
src/router/index.js

@ -0,0 +1,26 @@
import Vue from 'vue'
import VueRouter from 'vue-router'
import Home from '@/views/Home.vue'
Vue.use(VueRouter)
const routes = [
{
path: '/',
name: 'Home',
component: Home
},
{
path: '/about',
name: 'About',
component: () => import(/* webpackChunkName: "about" */ '@/views/About.vue')
}
]
const index = new VueRouter({
// mode: 'history',
base: process.env.BASE_URL,
routes
})
export default index

29
src/subpage/App.vue

@ -1,29 +0,0 @@
<template>
<div id="app">
<div id="nav">
<router-link to="/">Home</router-link> |
<router-link to="/about">About</router-link>
</div>
<router-view/>
</div>
</template>
<style lang="less">
#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>

12
src/subpage/main.js

@ -1,12 +0,0 @@
import Vue from 'vue'
import App from './App.vue'
import router from './router'
import store from '@/store'
Vue.config.productionTip = false
new Vue({
router,
store,
render: h => h(App)
}).$mount('#app')

21
src/subpage/router.js

@ -1,21 +0,0 @@
import Vue from 'vue'
import Router from 'vue-router'
import Home from './views/Home.vue'
import About from './views/About.vue'
Vue.use(Router)
export default new Router({
routes: [
{
path: '/',
name: 'home',
component: Home
},
{
path: '/about',
name: 'about',
component: About
}
]
})

5
src/subpage/views/About.vue

@ -1,5 +0,0 @@
<template>
<div class="about">
<h1>This is an about page</h1>
</div>
</template>

21
src/subpage/views/Home.vue

@ -1,21 +0,0 @@
<template>
<div class="home">
<img src="@/assets/logo.png">
<HelloWorld msg="多页面测试页"/>
</div>
</template>
<script>
// @ is an alias to /src
import HelloWorld from '@/components/HelloWorld.vue'
export default {
name: 'home',
components: {
HelloWorld
},
mounted() {
console.log(`这个是多页面测试页的主页:${this.$store.state.myname}`)
}
}
</script>

0
src/index/views/About.vue → src/views/About.vue

0
src/index/views/Home.vue → src/views/Home.vue

6
vue.config.js

@ -9,8 +9,8 @@ module.exports = {
// build 生成的文件名称 例: dist/index.html
filename: 'index.html'
},
// template 默认会去找 public/subpage.html 页面,如果找不到会使用 public/index.html 文件
// 输出文件会默认的推断为 subpage.html
subpage: 'src/subpage/main.js'
// template 默认会去找 public/app.html 页面,如果找不到会使用 public/index.html 文件
// 输出文件会默认的推断为 app.html
app: 'src/app/main.js'
}
}

Loading…
Cancel
Save