Skip to content

Commit 2c0d8f6

Browse files
committed
add vue-router
`yarn add vue-router`
1 parent 2d5be67 commit 2c0d8f6

File tree

4 files changed

+34
-8
lines changed

4 files changed

+34
-8
lines changed

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
"yarn": "^1.22.4"
2626
},
2727
"dependencies": {
28-
"vue": "^2.6.11"
28+
"vue": "^2.6.11",
29+
"vue-router": "^3.3.4"
2930
}
3031
}

src/app.vue

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,12 @@
44
<h1 class="title">Hello World!</h1>
55
</header>
66
<article>
7-
<p>{{ paragraph }}</p>
7+
<router-view></router-view>
8+
<ul>
9+
<li><router-link to="/">Home</router-link></li>
10+
<li><router-link to="/foo">Foo</router-link></li>
11+
<li><router-link to="/bar">Bar</router-link></li>
12+
</ul>
813
</article>
914
<footer>
1015
<address>w-tokyodo</address>
@@ -14,11 +19,7 @@
1419

1520
<script>
1621
export default {
17-
data() {
18-
return {
19-
paragraph: 'This is article.'
20-
}
21-
}
22+
//
2223
}
2324
</script>
2425

src/index.js

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,28 @@
11
import './index.scss';
22
import Vue from 'vue';
3+
import VueRouter from 'vue-router';
34
import App from './app.vue';
45

6+
Vue.use(VueRouter);
7+
8+
const Home = { template: '<div>Home</div>' };
9+
const Foo = { template: '<div>foo</div>' };
10+
const Bar = { template: '<div>bar</div>' };
11+
12+
const routes = [
13+
{ path: '/', component: Home },
14+
{ path: '/foo', component: Foo },
15+
{ path: '/bar', component: Bar }
16+
];
17+
18+
const router = new VueRouter({
19+
mode: 'history',
20+
routes: routes
21+
});
22+
523
new Vue({
624
el: '#app',
725
components: { App },
8-
template: '<App/>'
26+
template: '<App/>',
27+
router
928
});

yarn.lock

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4147,6 +4147,11 @@ vue-loader@^15.*:
41474147
vue-hot-reload-api "^2.3.0"
41484148
vue-style-loader "^4.1.0"
41494149

4150+
vue-router@^3.3.4:
4151+
version "3.3.4"
4152+
resolved "https://registry.yarnpkg.com/vue-router/-/vue-router-3.3.4.tgz#4e38abc34a11c41b6c3d8244449a2e363ba6250b"
4153+
integrity sha512-SdKRBeoXUjaZ9R/8AyxsdTqkOfMcI5tWxPZOUX5Ie1BTL5rPSZ0O++pbiZCeYeythiZIdLEfkDiQPKIaWk5hDg==
4154+
41504155
vue-style-loader@^4.1.0:
41514156
version "4.1.2"
41524157
resolved "https://registry.yarnpkg.com/vue-style-loader/-/vue-style-loader-4.1.2.tgz#dedf349806f25ceb4e64f3ad7c0a44fba735fcf8"

0 commit comments

Comments
 (0)