Skip to content
This repository was archived by the owner on Mar 25, 2020. It is now read-only.

Commit 3627675

Browse files
committedDec 1, 2016
最初のコミット
0 parents  commit 3627675

25 files changed

+319
-0
lines changed
 

‎.editorconfig

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
root = true
2+
3+
[*]
4+
indent_style = space
5+
end_of_line = lf
6+
charset = utf-8
7+
trim_trailing_whitespace = true
8+
insert_final_newline = true
9+
indent_size = 2

‎.gitignore

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
node_modules
2+
dist

‎package.json

+30
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
{
2+
"name": "vue-typescript-example-2",
3+
"version": "1.0.0",
4+
"description": "",
5+
"main": "main.js",
6+
"scripts": {
7+
"build": "webpack",
8+
"watch": "webpack --watch"
9+
},
10+
"keywords": [],
11+
"author": "",
12+
"license": "MIT",
13+
"dependencies": {
14+
"tslib": "^1.2.0",
15+
"vue": "^2.1.3",
16+
"vue-class-component": "^4.3.1",
17+
"vue-property-decorator": "^3.2.0",
18+
"vue-router": "^2.1.0",
19+
"vuex": "^2.0.0"
20+
},
21+
"devDependencies": {
22+
"extract-text-webpack-plugin": "^2.0.0-beta.4",
23+
"html-webpack-plugin": "^2.24.1",
24+
"ts-loader": "^1.2.2",
25+
"typescript": "^2.1.1",
26+
"vue-template-compiler": "^2.1.3",
27+
"vue-template-loader": "^0.1.2",
28+
"webpack": "^2.1.0-beta.27"
29+
}
30+
}

‎src/Form/Form.template.html

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
<modal @close="cancel" title="メッセージを書く">
2+
<template slot="body">
3+
<div class="form-group">
4+
<label for="title">タイトル</label>
5+
<input type="text" class="form-control" id="title">
6+
</div>
7+
<div class="form-group">
8+
<label for="message">メッセージ</label>
9+
<textarea class="form-control" id="message" rows="4"></textarea>
10+
</div>
11+
</template>
12+
<template slot="footer">
13+
<button class="btn btn-secondary" @click="cancel">キャンセル</button>
14+
<button class="btn btn-primary" @click="save">保存する</button>
15+
</template>
16+
</modal>

‎src/Form/Form.ts

+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
import * as Vue from 'vue'
2+
import Component from 'vue-class-component'
3+
import * as template from './Form.template.html'
4+
import Modal from '../modal/modal'
5+
6+
@Component(template<Form>({
7+
components: {
8+
Modal
9+
}
10+
}))
11+
export default class Form extends Vue {
12+
title = ''
13+
14+
save() {}
15+
16+
cancel() {
17+
this.$router.back()
18+
}
19+
}

‎src/Home/Home.template.html

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
<div>
2+
<jumbotron></jumbotron>
3+
<div class="container">
4+
<h2>これまでに寄せられたメッセージ</h2>
5+
<div class="card card-block" v-for="massage in messages">
6+
<div>{{ message.date }}</div>
7+
<h4>{{ message.title }}</h4>
8+
<p class="card-text">{{ message.message }}</p>
9+
</div>
10+
</div>
11+
<router-view></router-view>
12+
</div>

‎src/Home/Home.ts

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
import * as Vue from 'vue'
2+
import Component from 'vue-class-component'
3+
import * as template from './Home.template.html'
4+
import Jumbotron from '../jumbotron/jumbotron'
5+
6+
@Component(template<Home>({
7+
components: {
8+
Jumbotron
9+
}
10+
}))
11+
export default class Home extends Vue {
12+
messages = []
13+
}

‎src/Links/Links.template.html

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
<div></div>

‎src/Links/Links.ts

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
import * as Vue from 'vue'
2+
import Component from 'vue-class-component'
3+
import * as template from './Links.template.html'
4+
5+
@Component(template({}))
6+
export default class Links extends Vue {
7+
links = []
8+
}

‎src/Settings/Settings.template.html

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
<div></div>

‎src/Settings/Settings.ts

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
import * as Vue from 'vue'
2+
import Component from 'vue-class-component'
3+
import * as template from './Settings.template.html'
4+
5+
@Component(template({}))
6+
export default class Settings extends Vue {}

‎src/index.template.html

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
<div>
2+
<navbar></navbar>
3+
<router-view></router-view>
4+
</div>

‎src/index.ts

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
import * as Vue from 'vue'
2+
import * as template from './index.template.html'
3+
import router from './router'
4+
import Navbar from './navbar/navbar'
5+
6+
const vm = new Vue(template({
7+
components: {
8+
Navbar
9+
},
10+
router
11+
}))
12+
13+
vm.$mount('#app')

‎src/jumbotron/jumbotron.template.html

+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
<div class="jumbotron jumbotron-fluid">
2+
<div class="container">
3+
<h1 class="display-3">Happy Birthday!!</h1>
4+
<p class="lead">12月4日は香風智乃の誕生日です。</p>
5+
<hr class="my-2">
6+
<p>
7+
<span v-if="!isBirthday">今日は{{ today }}ですが</span>
8+
<span v-else>今日は{{ today }}、誕生日当日です!!</span>
9+
<span>メッセージを書いてみましょう!</span>
10+
</p>
11+
<p class="lead">
12+
<router-link class="btn btn-primary btn-lg" :to="{ name: 'new' }" role="button">
13+
メッセージを書く
14+
</router-link>
15+
</p>
16+
</div>
17+
</div>

‎src/jumbotron/jumbotron.ts

+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
import * as Vue from 'vue'
2+
import Component from 'vue-class-component'
3+
import * as template from './jumbotron.template.html'
4+
import { zero } from '../util'
5+
6+
function format(y: number, m: number, d: number) {
7+
return `${y}${zero(m)}${zero(d)}日`
8+
}
9+
10+
const today = new Date()
11+
const year = today.getFullYear()
12+
const month = today.getMonth() + 1
13+
const date = today.getDate()
14+
15+
@Component(template<Jumbotron>({}))
16+
export default class Jumbotron extends Vue {
17+
today = format(year, month, date)
18+
19+
isBirthday = month === 12 && date === 4
20+
}

‎src/modal/modal.template.html

+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
<div>
2+
<div class="modal fade in" style="display: block;">
3+
<div class="modal-dialog">
4+
<div class="modal-content">
5+
<div class="modal-header">
6+
<button class="close" @click="close"><span aria-hidden="true">&times;</span></button>
7+
<h4 class="modal-title">{{ title }}</h4>
8+
</div>
9+
<div class="modal-body">
10+
<slot name="body"></slot>
11+
</div>
12+
<div class="modal-footer">
13+
<slot name="footer"></slot>
14+
</div>
15+
</div>
16+
</div>
17+
</div>
18+
<div class="modal-backdrop fade in"></div>
19+
</div>

‎src/modal/modal.ts

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
import * as Vue from 'vue'
2+
import { Component, prop } from 'vue-property-decorator'
3+
import * as template from './modal.template.html'
4+
5+
@Component(template({}))
6+
export default class Modal extends Vue {
7+
@prop({type: null})
8+
title: string
9+
10+
close() {
11+
this.$emit('close')
12+
}
13+
}

‎src/navbar/navbar.template.html

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
<nav class="navbar navbar-light bg-faded">
2+
<router-link class="navbar-brand" :to="{name: 'home'}">
3+
Vue.jsとTypeScriptのサンプル2
4+
</router-link>
5+
<ul class="nav navbar-nav">
6+
<router-link tag="li" :to="{name: 'home'}" class="nav-item">
7+
<a class="nav-link">ホーム</a>
8+
</router-link>
9+
<router-link tag="li" :to="'/links'" class="nav-item">
10+
<a class="nav-link">リンク一覧</a>
11+
</router-link>
12+
<router-link tag="li" :to="'/settings'" class="nav-item">
13+
<a class="nav-link">設定</a>
14+
</router-link>
15+
</ul>
16+
</nav>

‎src/navbar/navbar.ts

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
import * as Vue from 'vue'
2+
import Component from 'vue-class-component'
3+
import * as template from './navbar.template.html'
4+
5+
@Component(template({}))
6+
export default class Navbar extends Vue {}

‎src/router.ts

+24
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
import * as Vue from 'vue'
2+
import * as VueRouter from 'vue-router'
3+
4+
import Form from './Form/Form'
5+
import Home from './Home/Home'
6+
import Links from './Links/Links'
7+
import Settings from './Settings/Settings'
8+
9+
Vue.use(VueRouter)
10+
11+
export default new VueRouter({
12+
routes: [
13+
{
14+
path: '/',
15+
component: Home,
16+
name: 'home',
17+
children: [
18+
{ path: 'new', component: Form, name: 'new' }
19+
]
20+
},
21+
{ path: '/links', component: Links, name: 'links' },
22+
{ path: '/settings', component: Settings, name: 'settings' }
23+
]
24+
})

‎src/template.d.ts

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
declare module '*.html' {
2+
import * as Vue from 'vue'
3+
import { ComponentOptions } from 'vue'
4+
5+
var template: <V extends Vue>(options: ComponentOptions<V>) => ComponentOptions<V>
6+
7+
export = template
8+
}

‎src/util.ts

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
export function toInt(n: number) {
2+
return Math.floor(n)
3+
}
4+
5+
export function zero(n: number) {
6+
return ('0' + n).slice(-2)
7+
}

‎template.html

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
<!DOCTYPE html>
2+
<html lang="ja">
3+
<head>
4+
<meta charset="UTF-8">
5+
<title>Vue.jsとTypeScriptのサンプル2</title>
6+
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0-alpha.5/css/bootstrap.min.css" integrity="sha384-AysaV+vQoT3kOAXZkl02PThvDr8HYKPZhNT5h/CXfBThSRXQ6jW5DO2ekP5ViFdi" crossorigin="anonymous">
7+
</head>
8+
<body>
9+
<div id="app"></div>
10+
</body>
11+
</html>

‎tsconfig.json

+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
{
2+
"compilerOptions": {
3+
"module": "commonjs",
4+
"target": "es5",
5+
"noImplicitAny": true,
6+
"sourceMap": false,
7+
"strictNullChecks": true,
8+
"typeRoots": [
9+
"./node_modules/@types"
10+
],
11+
"lib": [
12+
"dom",
13+
"es5",
14+
"es2015.promise"
15+
],
16+
"noEmitHelpers": true,
17+
"experimentalDecorators": true,
18+
"importHelpers": true
19+
}
20+
}

‎webpack.config.js

+24
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
const HTMLWebpackPlugin = require('html-webpack-plugin')
2+
const ExtractTextPlugin = require('extract-text-webpack-plugin')
3+
4+
module.exports = {
5+
entry: './src/index.ts',
6+
output: {
7+
filename: '[name].js',
8+
path: './dist'
9+
},
10+
module: {
11+
loaders: [
12+
{ test: /\.tsx?$/, loader: 'ts-loader' },
13+
{ test: /\.scss$/, loader: ExtractTextPlugin.extract(['css-loader', 'sass-loader']) },
14+
{ test: /\.template\.html$/, loader: 'vue-template-loader' }
15+
]
16+
},
17+
resolve: {
18+
extensions: ['.ts', '.js']
19+
},
20+
plugins: [
21+
new HTMLWebpackPlugin({ template: './template.html' }),
22+
new ExtractTextPlugin('styles.css')
23+
]
24+
}

0 commit comments

Comments
 (0)
This repository has been archived.