Skip to content

Commit 08b759a

Browse files
committed
reconstruct project, using vue router
1 parent d773de1 commit 08b759a

37 files changed

+488
-30
lines changed

.eslintrc.js

+2
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@ module.exports = {
1313
rules: {
1414
'no-console': process.env.NODE_ENV === 'production' ? 'warn' : 'off',
1515
'no-debugger': process.env.NODE_ENV === 'production' ? 'warn' : 'off',
16+
'no-param-reassign': 'off',
17+
'no-use-before-define': 'off',
1618
},
1719
overrides: [
1820
{

src/App.vue

+2-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,8 @@
33
<div id="nav">
44
<router-link to="/">Home</router-link> |
55
<router-link to="/javascript">JavaScript</router-link> |
6-
<router-link to="/css">CSS</router-link>
6+
<router-link to="/css">CSS</router-link> |
7+
<router-link to="/vue">Vue</router-link>
78
</div>
89
<router-view/>
910
</div>
File renamed without changes.
File renamed without changes.

src/components/utils/FeTabs.vue renamed to src/components/FeTabs.vue

+2-1
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ export default {
4949
},
5050
handlerTabPaneClick(pane) {
5151
this.current = pane.name;
52+
this.$emit('change', this.current);
5253
},
5354
},
5455
mounted() {
@@ -73,7 +74,7 @@ export default {
7374
border-right: 1px solid #42b983;
7475
display: inline-block;
7576
width: 120px;
76-
padding: auto 12px;
77+
padding: 0 4px;
7778
text-align: center;
7879
color: #42b983;
7980
&.current {
File renamed without changes.

src/components/javascript/Promise.vue

Whitespace-only changes.

src/main.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import Vue from 'vue';
22
import App from './App.vue';
33
import router from './router';
44
import store from './store';
5-
import Utils from './components/utils';
5+
import Utils from './components';
66
import './assets/style/index.scss';
77

88
Vue.config.productionTip = false;

src/router/css.js

+30
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
export default [
2+
{
3+
path: 'horizontalverticalcenter',
4+
name: '水平垂直居中',
5+
component() {
6+
return import(/* webpackChunkName: "HorizontalVerticalCenter" */ '@/views/css/HorizontalVerticalCenter.vue');
7+
},
8+
},
9+
{
10+
path: 'flexbox',
11+
name: 'Flex布局',
12+
component() {
13+
return import(/* webpackChunkName: "FlexBox" */ '@/views/css/FlexBox.vue');
14+
},
15+
},
16+
{
17+
path: 'twocolumn',
18+
name: '两栏布局',
19+
component() {
20+
return import(/* webpackChunkName: "TwoColumn" */ '@/views/css/TwoColumn.vue');
21+
},
22+
},
23+
{
24+
path: 'threecolumn',
25+
name: '三栏布局',
26+
component() {
27+
return import(/* webpackChunkName: "ThreeColumn" */ '@/views/css/ThreeColumn.vue');
28+
},
29+
},
30+
];

src/router/index.js

+14
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,11 @@
11
import Vue from 'vue';
22
import VueRouter from 'vue-router';
33
import Home from '../views/Home.vue';
4+
import JavaScriptRoutes from './javascript';
5+
import CssRoutes from './css';
6+
import VueRoutes from './vue';
47

8+
console.log('JavaScriptRoutes', JavaScriptRoutes);
59
Vue.use(VueRouter);
610

711
const routes = [
@@ -19,13 +23,23 @@ const routes = [
1923
component() {
2024
return import(/* webpackChunkName: "javascript" */ '../views/JavaScript.vue');
2125
},
26+
children: JavaScriptRoutes,
2227
},
2328
{
2429
path: '/css',
2530
name: 'Css',
2631
component() {
2732
return import(/* webpackChunkName: "css" */ '../views/Css.vue');
2833
},
34+
children: CssRoutes,
35+
},
36+
{
37+
path: '/vue',
38+
name: 'Vue',
39+
component() {
40+
return import(/* webpackChunkName: "vue" */ '../views/Vue.vue');
41+
},
42+
children: VueRoutes,
2943
},
3044
];
3145

src/router/javascript.js

+37
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
export default [
2+
{
3+
path: 'eventloop',
4+
name: '事件循环',
5+
component() {
6+
return import(/* webpackChunkName: "EventLoop" */ '@/views/javascript/EventLoop.vue');
7+
},
8+
},
9+
{
10+
path: 'asynchronous',
11+
name: '异步',
12+
component() {
13+
return import(/* webpackChunkName: "Asynchronous" */ '@/views/javascript/Asynchronous.vue');
14+
},
15+
},
16+
{
17+
path: 'crossorigin',
18+
name: '跨域',
19+
component() {
20+
return import(/* webpackChunkName: "CrossOrigin" */ '@/views/javascript/CrossOrigin.vue');
21+
},
22+
},
23+
{
24+
path: 'this',
25+
name: 'this',
26+
component() {
27+
return import(/* webpackChunkName: "This" */ '@/views/javascript/This.vue');
28+
},
29+
},
30+
{
31+
path: 'promise',
32+
name: 'Promise',
33+
component() {
34+
return import(/* webpackChunkName: "Promise" */ '@/views/javascript/Promise.vue');
35+
},
36+
},
37+
];

src/router/vue.js

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export default [];

src/views/Css.vue

+23-11
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,37 @@
11
<template>
22
<div class="css">
3-
<FeTabs>
4-
<FeTabPane name="TwoColumn" label="两栏布局">
5-
<TwoColumn/>
6-
</FeTabPane>
7-
<FeTabPane name="ThreeColumn" label="三栏布局">
8-
<ThreeColumn/>
3+
<FeTabs @change="handlerChange">
4+
<FeTabPane
5+
:name="tab.name"
6+
:label="tab.label"
7+
v-for="tab of tabs"
8+
:key="tab.name"
9+
>
910
</FeTabPane>
1011
</FeTabs>
12+
<router-view/>
1113
</div>
1214
</template>
1315

1416
<script>
15-
import TwoColumn from '@/components/css/TwoColumn.vue';
16-
import ThreeColumn from '@/components/css/ThreeColumn.vue';
17+
import CssTabs from '@/router/css';
1718
1819
export default {
1920
name: 'Css',
20-
components: {
21-
TwoColumn,
22-
ThreeColumn,
21+
data() {
22+
return {
23+
tabs: CssTabs.map(({ path, name }) => ({
24+
name: path,
25+
label: name,
26+
})),
27+
};
28+
},
29+
methods: {
30+
handlerChange(path) {
31+
if (!this.$route.path.includes(path)) {
32+
this.$router.push(`/css/${path}`);
33+
}
34+
},
2335
},
2436
};
2537
</script>

src/views/JavaScript.vue

+23-11
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,37 @@
11
<template>
22
<div class="javascript">
3-
<FeTabs>
4-
<FeTabPane name="EventLoop" label="事件循环">
5-
<EventLoop />
6-
</FeTabPane>
7-
<FeTabPane name="CrossOrigin" label="跨域">
8-
<CrossOrigin />
3+
<FeTabs @change="handlerChange">
4+
<FeTabPane
5+
:name="tab.name"
6+
:label="tab.label"
7+
v-for="tab of tabs"
8+
:key="tab.name"
9+
>
910
</FeTabPane>
1011
</FeTabs>
12+
<router-view/>
1113
</div>
1214
</template>
1315

1416
<script>
15-
import EventLoop from '@/components/javascript/EventLoop.vue';
16-
import CrossOrigin from '@/components/javascript/CrossOrigin.vue';
17+
import JavaScriptTabs from '@/router/javascript';
1718
1819
export default {
1920
name: 'JavaScript',
20-
components: {
21-
EventLoop,
22-
CrossOrigin,
21+
data() {
22+
return {
23+
tabs: JavaScriptTabs.map(({ path, name }) => ({
24+
name: path,
25+
label: name,
26+
})),
27+
};
28+
},
29+
methods: {
30+
handlerChange(path) {
31+
if (!this.$route.path.includes(path)) {
32+
this.$router.push(`/javascript/${path}`);
33+
}
34+
},
2335
},
2436
};
2537
</script>

src/views/Vue.vue

+42
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
<template>
2+
<div class="vue">
3+
<FeTabs @change="handlerChange">
4+
<FeTabPane
5+
:name="tab.name"
6+
:label="tab.label"
7+
v-for="tab of tabs"
8+
:key="tab.name"
9+
>
10+
</FeTabPane>
11+
</FeTabs>
12+
<router-view/>
13+
</div>
14+
</template>
15+
16+
<script>
17+
import VueTabs from '@/router/vue';
18+
19+
export default {
20+
name: 'Vue',
21+
data() {
22+
return {
23+
tabs: VueTabs.map(({ path, name }) => ({
24+
name: path,
25+
label: name,
26+
})),
27+
};
28+
},
29+
methods: {
30+
handlerChange(path) {
31+
if (!this.$route.path.includes(path)) {
32+
this.$router.push(`/vue/${path}`);
33+
}
34+
},
35+
},
36+
};
37+
</script>
38+
39+
<style lang="scss">
40+
.vue {
41+
}
42+
</style>
File renamed without changes.
File renamed without changes.
+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
<template>
2+
<div class="horizontal-vertical-center">
3+
4+
</div>
5+
</template>
6+
7+
<script>
8+
export default {
9+
name: 'HorizontalVerticalCenter',
10+
};
11+
</script>
12+
13+
<style lang="scss">
14+
.orizontal-vertical-center {
15+
16+
}
17+
</style>
File renamed without changes.
File renamed without changes.

src/components/javascript/CrossOrigin.vue renamed to src/views/javascript/CrossOrigin.vue

+6-3
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,6 @@
99
// 跨域
1010
export default {
1111
name: 'CrossOrigin',
12-
components: {
13-
14-
},
1512
data() {
1613
return {
1714
@@ -24,10 +21,16 @@ export default {
2421
},
2522
methods: {
2623
// Nginx设置跨域请求头, 可以直接获取
24+
// *表示接受任意域名
2725
// add_header 'Access-Control-Allow-Origin' *;
26+
// 是否允许发送Cookie
2827
// add_header 'Access-Control-Allow-Credentials' 'true';
28+
// 表示服务器支持的所有跨域方法
2929
// add_header 'Access-Control-Allow-Methods' 'GET, POST, OPTIONS';
3030
getHelloJsCORS() {
31+
// 简单请求指的是get post options
32+
// 浏览器发现请求为简单的ajax跨源请求, 就自动在请求头加上Origin字段, 用来说明此次请求来自哪个源
33+
// 如果Origin指定的源不在许可范围之内, 则回应的头中不包含Access-Control-Allow-Origin字段, 因此浏览器知道出错了, 从而抛出一个错误
3134
fetch('http://192.168.3.4:5001/static/hello.js')
3235
.then((res) => {
3336
console.log('CORS', res);

src/components/javascript/EventLoop.vue renamed to src/views/javascript/EventLoop.vue

+1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
<template>
22
<div class="event-loop">
3+
事件循环
34
</div>
45
</template>
56

src/views/javascript/Promise.vue

+40
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
<template>
2+
<div class="promise">
3+
<FeButton @click="promisePractise"> Promise练习 </FeButton>
4+
</div>
5+
</template>
6+
7+
<script>
8+
import PromiseAPlus from './Promise/PromiseAPlus';
9+
// Promise
10+
export default {
11+
name: 'Promise',
12+
data() {
13+
return {
14+
flag: false,
15+
};
16+
},
17+
methods: {
18+
promisePractise() {
19+
const p = new PromiseAPlus((resolve, reject) => {
20+
this.flag = !this.flag;
21+
if (this.flag === false) {
22+
resolve(1);
23+
} else {
24+
reject(2);
25+
}
26+
}).then((res) => {
27+
console.log('res', res);
28+
}, (reason) => {
29+
console.log('reason', reason);
30+
});
31+
console.log(p);
32+
},
33+
},
34+
};
35+
</script>
36+
37+
<style lang="scss">
38+
.promise {
39+
}
40+
</style>

0 commit comments

Comments
 (0)