Skip to content

Commit 162d25a

Browse files
committed
SampleをTypeScriptで実装
1 parent 1e6fe18 commit 162d25a

File tree

4 files changed

+78
-78
lines changed

4 files changed

+78
-78
lines changed

public/index.html

+18-15
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,20 @@
11
<!DOCTYPE html>
22
<html>
3-
<head>
4-
<meta charset="utf-8">
5-
<meta http-equiv="X-UA-Compatible" content="IE=edge">
6-
<meta name="viewport" content="width=device-width,initial-scale=1.0">
7-
<link rel="icon" href="<%= BASE_URL %>favicon.ico">
8-
<title>vue-typescript-sample</title>
9-
</head>
10-
<body>
11-
<noscript>
12-
<strong>We're sorry but vue-typescript-sample doesn't work properly without JavaScript enabled. Please enable it to continue.</strong>
13-
</noscript>
14-
<div id="app"></div>
15-
<!-- built files will be auto injected -->
16-
</body>
17-
</html>
3+
4+
<head>
5+
<meta charset="utf-8">
6+
<meta http-equiv="X-UA-Compatible" content="IE=edge">
7+
<meta name="viewport" content="width=device-width,initial-scale=1.0">
8+
<link rel="icon" href="<%= BASE_URL %>favicon.ico">
9+
<title>vue-typescript-sample</title>
10+
</head>
11+
12+
<body>
13+
<noscript>
14+
<strong>We're sorry but vue-typescript-sample doesn't work properly without JavaScript enabled. Please enable it to continue.</strong>
15+
</noscript>
16+
<div id="app"></div>
17+
<!-- built files will be auto injected -->
18+
</body>
19+
20+
</html>

src/App.vue

+8-4
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,24 @@
11
<template>
22
<div id="app">
33
<img src="./assets/logo.png">
4-
<HelloWorld msg="Welcome to Your Vue.js + TypeScript App"/>
4+
<HelloVue val="Vue" v-on:handle-click="handleClickButton($event)" />
55
</div>
66
</template>
77

88
<script lang="ts">
99
import { Component, Vue } from 'vue-property-decorator';
10-
import HelloWorld from './components/HelloWorld.vue';
10+
import HelloVue from './components/HelloVue.vue';
1111
1212
@Component({
1313
components: {
14-
HelloWorld,
14+
HelloVue,
1515
},
1616
})
17-
export default class App extends Vue {}
17+
export default class App extends Vue {
18+
handleClickButton($event: string) {
19+
console.log($event);
20+
}
21+
}
1822
</script>
1923

2024
<style lang="scss">

src/components/HelloVue.vue

+52
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
<template>
2+
<div>
3+
<h1>Hello {{ value }}</h1>
4+
<input type="text" v-bind:value="inputValue" v-on:input="handleInput($event)" />
5+
<button v-on:click="handleClick()" v-bind:disabled="isDisabled">button</button>
6+
</div>
7+
</template>
8+
9+
<script lang="ts">
10+
import { Component, Prop, Emit, Vue } from 'vue-property-decorator';
11+
12+
@Component
13+
export default class HelloVue extends Vue {
14+
/** props */
15+
@Prop() private val!: string;
16+
17+
/** emit */
18+
@Emit('handle-click')
19+
clickButton(val: string) {}
20+
21+
/** data */
22+
value: string = this.val;
23+
inputValue: string = '';
24+
25+
/** lifecylce hook */
26+
mounted() {
27+
console.log('mounted');
28+
}
29+
30+
/** computed */
31+
get isDisabled(): boolean {
32+
return this.inputValue === '';
33+
}
34+
35+
/** method */
36+
handleInput($event: any): void {
37+
this.inputValue = $event.target.value;
38+
}
39+
handleClick(): void {
40+
if (this.inputValue === '') {
41+
return;
42+
}
43+
this.value = this.inputValue;
44+
this.inputValue = '';
45+
this.clickButton(this.value);
46+
}
47+
}
48+
</script>
49+
50+
<!-- Add "scoped" attribute to limit CSS to this component only -->
51+
<style scoped lang="scss">
52+
</style>

src/components/HelloWorld.vue

-59
This file was deleted.

0 commit comments

Comments
 (0)