Skip to content

Commit 6b99821

Browse files
committed
Added instructions
1 parent ec1f0aa commit 6b99821

File tree

8 files changed

+773
-7
lines changed

8 files changed

+773
-7
lines changed

README.md

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,9 @@ Visual Studio Code, TypeScript, Element 編
1414
## ハンズオン手順書
1515

1616
- [Lab 0 - 開発環境の準備](instructions/lab00.md)
17-
- Lab 1 - プロジェクトの作成 `後日公開予定`
18-
- Lab 2 - 基本的なレンダリング `後日公開予定`
19-
- Lab 3 - テーブルの作成 `後日公開予定`
20-
- Lab 4 - フォームの作成 `後日公開予定`
21-
- Option 1 - API の接続 `後日公開予定`
22-
- Option 2 - さまざまなレンダリング `後日公開予定`
17+
- [Lab 1 - プロジェクトの作成](instructions/lab01.md)
18+
- [Lab 2 - 基本的なレンダリング](instructions/lab02.md)
19+
- [Lab 3 - テーブルの作成](instructions/lab03.md)
20+
- [Lab 4 - フォームの作成](instructions/lab04.md)
21+
- [Option 1 - API の接続](instructions/opt01.md)
22+
- [Option 2 - さまざまなレンダリング](instructions/opt02.md)

instructions/lab00.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,4 +26,4 @@
2626

2727
---
2828

29-
[Next(準備中)](../README.md)
29+
[Next](lab01.md)

instructions/lab01.md

Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
# Lab 1 - プロジェクトの作成
2+
3+
## Exercise 1: Vue CLI でのプロジェクト新規作成
4+
5+
1. ターミナルやコマンドプロンプトで、プロジェクトを作成するディレクトリに移動します。 `˜/src` 以下に作成する場合は以下のように実行します(ディレクトリの場所は任意です)。
6+
7+
```bash
8+
cd ˜/src
9+
```
10+
11+
1. Vue CLI でプロジェクトを新規作成します。まず、以下のコマンドを実行します(コマンド実行後はそのまま待機しておいてください)。以下ではプロジェクト名を `vue-lab` としています(プロジェクト名は任意です)。
12+
13+
```bash
14+
vue create vue-lab
15+
```
16+
17+
1. 実行後のプロンプト `Please pick a preset` では、以下のように `Manually select features` を選択します。
18+
19+
```bash
20+
? Please pick a preset:
21+
default (babel, eslint)
22+
❯ Manually select features
23+
```
24+
25+
1. 次のプロンプト `Check the features needed for your project` では、以下のよう `TypeScript``Router` を選択します。
26+
27+
```bash
28+
? Check the features needed for your project:
29+
◯ Babel
30+
❯◉ TypeScript
31+
◯ Progressive Web App (PWA) Support
32+
◉ Router
33+
◯ Vuex
34+
◯ CSS Pre-processors
35+
◯ Linter / Formatter
36+
◯ Unit Testing
37+
◯ E2E Testing
38+
```
39+
40+
1. **(重要)** 次のプロンプト `Use class-style component syntax?` では、 `n` を選択してください。
41+
42+
このハンズオンでは、 TypeScript では開発に、クラススタイルではなく、 `Vue.Extend` を使った記法を採用しています。主な理由は、[[Abandoned] Class API proposal: Update: the Class API proposal is being dropped.](https://github.com/vuejs/rfcs/pull/17#issuecomment-494242121) によるためです。
43+
44+
1. 次以降のプロンプトでは以下の設定になるように選択してください。
45+
46+
```bash
47+
? Use Babel alongside TypeScript for auto-detected polyfills? No
48+
? Use history mode for router? (Requires proper server setup for index fallback in production) Yes
49+
? Where do you prefer placing config for Babel, PostCSS, ESLint, etc.? In dedicated config files
50+
? Save this as a preset for future projects? No
51+
? Pick the package manager to use when installing dependencies:
52+
Use Yarn
53+
❯ Use NPM
54+
```
55+
56+
Yarn に慣れている方は `Use Yarn` を選択しても構いません(このハンズオンでは、npm を前提に説明を進めますので、適宜読み替えてください)
57+
58+
## Exercise 2: プロジェクトの起動
59+
60+
1. `vue create` の処理が完了したら、カレントディレクトリを Vue CLI で生成したディレクトリに移動し(この例では `vue-lab`)、以下のコマンドを実行してプロジェクトを起動します。
61+
62+
```bash
63+
cd vue-lab
64+
npm run serve
65+
```
66+
67+
1. `npm run serve` の実行が完了したら、ブラウザで `http://localhost:8080/` にアクセスします。
68+
69+
1. ブラウザに 「Welcome to Your Vue.js + TypeScript App」 等と表示されていれば、無事にプロジェクトの作成が成功しています。
70+
71+
`vue create` コマンドの詳細は [Creating a Project \| Vue CLI](https://cli.vuejs.org/guide/creating-a-project.html) を確認してください。
72+
73+
---
74+
75+
[Previous](lab00.md) | [Next](lab02.md)

instructions/lab02.md

Lines changed: 132 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,132 @@
1+
# Lab 2 - 基本的なレンダリング
2+
3+
## Exercise 1: テキストバインディング
4+
5+
1. トップページを、TypeScript で定義したプロパティをレンダリングするように変更してみます。まず `src/views/Home.vue` を開き、 `<script>` タグ内を以下のように編集します(既存のコードは削除して構いません)。
6+
7+
```ts
8+
<script lang="ts">
9+
import Vue from "vue";
10+
11+
export default Vue.extend({
12+
data() {
13+
return {
14+
msg: "Hello Vue.js!"
15+
};
16+
}
17+
});
18+
</script>
19+
```
20+
21+
1. 次にHTML部分となるテンプレートを変更して、 TypeScript で実装した `msg` をレンダリングするうように変更します(既存のマークアップは削除して構いません)。
22+
23+
```html
24+
<template>
25+
<div class="home">
26+
<h3>テキストバインディング</h3>
27+
<span>{{ msg }}</span>
28+
</div>
29+
</template>
30+
```
31+
32+
ブラウザに「Hello Vue!」と表示されていれば成功です。
33+
34+
1. 次に `Home.vue` のスタイルが左寄せになるように `<style>` タグを追加します。
35+
36+
```css
37+
<style scoped>
38+
.home {
39+
text-align: left;
40+
}
41+
</style>
42+
```
43+
44+
## Exercise 2: リストレンダリング
45+
46+
1. まず、リスト要素の型を定義するインターフェース `Item` を定義しておきます。ここでは、便宜的にインターフェースの定義箇所を Home.vuescriptタグ内にそのまま追加するようにしています。
47+
48+
```ts
49+
<script lang="ts">
50+
import Vue from "vue";
51+
52+
// ここにインターフェースを追加
53+
declare interface Item {
54+
id: number;
55+
name: string;
56+
}
57+
58+
// 以下省略
59+
</script>
60+
```
61+
62+
1. scriptタグ内の `data()` 内に、リストを表現する配列 `items` を実装します。
63+
64+
```ts
65+
import Vue from "vue";
66+
67+
// 途中省略
68+
69+
export default Vue.extend({
70+
data() {
71+
return {
72+
msg: "Hello Vue.js!",
73+
items: [
74+
{
75+
id: 1,
76+
name: "キーボード"
77+
},
78+
{
79+
id: 2,
80+
name: "マウス"
81+
}
82+
] as Item[]
83+
};
84+
}
85+
});
86+
```
87+
88+
1. 続けて、TypeScript で実装した `items` をレンダリングするうように `<template>` に以下を追加します。
89+
90+
```html
91+
<template>
92+
<div class="home">
93+
<!-- 途中省略 -->
94+
<h3>リストレンダリング</h3>
95+
<ul id="item-list">
96+
<li v-for="item in items" :key="item.id">
97+
{{item.name}}
98+
</li>
99+
</ul>
100+
</div>
101+
</template>
102+
```
103+
104+
ブラウザに Item のリストが2行表示されていれば成功です。
105+
106+
## Exercise 3: イベントハンドリング
107+
108+
1. クリックイベントに対応するイベントハンドラを `<script>` タグ内にメソッドとして実装します。
109+
110+
```ts
111+
data() {
112+
// 途中省略
113+
},
114+
// ここにメソッドを追加する
115+
methods: {
116+
onClick(): void {
117+
alert(this.msg);
118+
}
119+
}
120+
```
121+
122+
1. テンプレートには `v-on` を使ったイベントに対応するをボタンを実装します。
123+
124+
```html
125+
<h3>イベントハンドリング</h3>
126+
<button v-on:click="onClick">実行</button>
127+
```
128+
129+
ボタンをクリックして「Hello Vue!」アラートが表示されれば成功です。
130+
131+
---
132+
[Previous](lab01.md) | [Next](lab03.md)

instructions/lab03.md

Lines changed: 164 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,164 @@
1+
# Lab 3 - テーブルの作成
2+
3+
## Exercise 1: Element の導入
4+
5+
1. Vue.js で利用できる UI ライブラリとして提供されている [Element](https://element.eleme.io/) を導入します。Element は Vue CLI のプラグインとしてインストールすることができますので、以下のコマンドを実行します。
6+
7+
```bash
8+
vue add element
9+
```
10+
11+
1. CLI のプロンプトでは以下のように設定します。
12+
13+
```bash
14+
? How do you want to import Element? : Fully import
15+
? Do you wish to overwrite Element's SCSS variables? : No
16+
? Choose the locale you want to load: ja
17+
```
18+
19+
1. Element のインストール後、全体のレイアウトを調整するために `App.vue` を以下のように書き換えて下さい。( `<script>` タグは不要です)
20+
21+
```html
22+
<template>
23+
<div id="app">
24+
<el-container>
25+
<el-aside>
26+
<el-menu id="nav">
27+
<el-menu-item>
28+
<router-link to="/">Home</router-link>
29+
</el-menu-item>
30+
<el-menu-item>
31+
<router-link to="/about">About</router-link>
32+
</el-menu-item>
33+
</el-menu>
34+
</el-aside>
35+
<el-main>
36+
<router-view />
37+
</el-main>
38+
</el-container>
39+
</div>
40+
</template>
41+
42+
<style>
43+
#app {
44+
font-family: 'Avenir', Helvetica, Arial, sans-serif;
45+
-webkit-font-smoothing: antialiased;
46+
-moz-osx-font-smoothing: grayscale;
47+
text-align: center;
48+
color: #2c3e50;
49+
margin-top: 60px;
50+
}
51+
</style>
52+
```
53+
54+
## Exercise 2: テーブル画面の追加
55+
56+
1. `views` ディレクトリ配下に `Table.vue` ファイルを新規に追加します。この時点ではファイルの中身は何も実装しなくて構いません。
57+
58+
1. 次に、 [Vue Router](https://router.vuejs.org/ja/) の機能を使って、テーブル画面に遷移できるように `router.ts` を以下のように編集します。
59+
60+
```ts
61+
// (途中省略)
62+
// 1. importに以下を追加します
63+
import Table from './views/Table.vue';
64+
65+
Vue.use(Router);
66+
67+
export default new Router({
68+
mode: 'history',
69+
base: process.env.BASE_URL,
70+
routes: [
71+
// (途中省略)
72+
// 2. routesに以下を追加します
73+
{
74+
path: '/table',
75+
name: 'table',
76+
component: Table
77+
}
78+
]
79+
});
80+
```
81+
82+
1. 画面左のメニューにテーブル画面へのリンクが表示されるよう `App.vue` に以下を追加します。
83+
84+
```html
85+
<el-menu-item>
86+
<router-link to="/table">Table</router-link>
87+
</el-menu-item>
88+
```
89+
90+
この時点では、コンソールに `[Vue warn]: Failed to mount component: template or render function not defined.` の警告が出ますがそのまま進めます。
91+
92+
## Exercise 3: Element の Table コンポーネント を使ったテーブルの実装
93+
94+
1. テーブルのデータとなるオブジェクトを TypeScript 側に実装するため、 `Table.vue` を開き、 `<script>` タグを以下のように実装します。
95+
96+
```ts
97+
<script lang="ts">
98+
import Vue from "vue";
99+
100+
// NoteBook型の定義
101+
declare interface NoteBook {
102+
id: number;
103+
brand: string;
104+
name: string;
105+
isUsed: boolean;
106+
}
107+
108+
// Table画面のビューモデル
109+
export default Vue.extend({
110+
data() {
111+
return {
112+
noteBooks: [
113+
{
114+
id: 1001,
115+
brand: "Microsoft",
116+
name: "Surface Go",
117+
isUsed: false
118+
},
119+
{
120+
id: 1002,
121+
brand: "Apple",
122+
name: "MacBook Air",
123+
isUsed: true
124+
}
125+
] as NoteBook[]
126+
};
127+
}
128+
});
129+
</script>
130+
```
131+
132+
1. 次に [Element の Table コンポーネント](https://element.eleme.io/#/en-US/component/table) は 以下のように `<template>` タグをマークアップすることで簡単に高機能なテーブルを作成することができます。
133+
134+
```html
135+
<template>
136+
<div class="table">
137+
<el-table
138+
:data="noteBooks"
139+
:default-sort="{prop: 'id', order: 'ascending'}"
140+
>
141+
<el-table-column prop="id" label="ID" sortable> </el-table-column>
142+
<el-table-column prop="brand" label="メーカー"> </el-table-column>
143+
<el-table-column prop="name" label="機種名"> </el-table-column>
144+
<el-table-column prop="isUsed" label="利用中">
145+
<template slot-scope="scope">
146+
<i class="el-icon-check" v-if="scope.row.isUsed"></i>
147+
</template>
148+
</el-table-column>
149+
</el-table>
150+
</div>
151+
</template>
152+
153+
<style scoped>
154+
.table {
155+
text-align: left;
156+
}
157+
</style>
158+
```
159+
160+
ブラウザで `http://localhost:8080/table` を表示し、ソート機能付きのテーブルがレンダリングされていれば成功です。
161+
162+
---
163+
164+
[Previous](lab02.md) | [Next](lab04.md)

0 commit comments

Comments
 (0)