Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Nuxt.js in TypeScript

nunulk
January 17, 2019

Nuxt.js in TypeScript

やってみた

nunulk

January 17, 2019
Tweet

More Decks by nunulk

Other Decks in Programming

Transcript

  1. ࣗݾ঺հ 
 const name: Name = 'nunulk(͵͵Δ͘)' let job: Job

    = 'ϑϦʔϥϯεͷ΢ΣϒΞϓϦέʔγϣϯΤϯδχΞ' let languages: Language[] = [
 'C/C++', ‘Java', 'PHP', ‘JavaScript', ‘TypeScript’,
 ] let frameworks: Framework[] = [
 'CodeIgniter', 'Symfony', 'CakePHP', ‘Laravel', ]
  2. ຊ೔࿩͢͜ͱ • Nuxt.js ͱ TypeScript ͷ঺հ • Nuxt.js ͷ TypeScript

    ରԠঢ়گ • Nuxt.js Λ TypeScript Ͱಈ͔ͯ͠ΈΔ
  3. Nuxt.js ͱ͸ • vue, vuex, vue-router, vue-server-renderer, vue-meta શ෦ೖΓ •

    ϧʔςΟϯάͷࣗಈԽɺmiddleware • Vue ίϯϙʔωϯτͱ Vuex Store ͷ࣮૷ʹઐ೦ Ͱ͖Δ
  4. TypeScript ͱ͸ let t: [string, number] = ['Jan', 1] enum

    Color { Red, Green, Blue } const c: Color = Color.Green interface Food { name: string calories: number } class Menu { items: string[] pages: number constructor(items: string[], pages: number) { this.items = items this.pages = pages } }
  5. υϝΠϯͷܕͱ RootState ͷఆٛ 
 export interface Task { title: string;

    status: TaskStatus; } export enum TaskStatus { Open = 'open', Doing = 'doing', Closed = 'closed', } 
 export interface RootState { tasks: Task[]; }
  6. Vue, Decorator ͷ import 
 <script lang="ts"> import { Vue,

    Component, Prop } from 'nuxt-property-decorator' @Component({}) export default class extends Vue { @Prop() value: Task }
  7. Store ͷ࣮૷ export const state = (): RootState => ({

    tasks: [], }) export const mutations: MutationTree<RootState> = { setTasks(state: RootState, tasks: Task[]): void { state.tasks = tasks }, addTask(state: RootState, task: Task): void { state.tasks.push({...task}) }, }
 
 export const actions: ActionTree<RootState, RootState> = { async fetchTasks({ commit }) { const tasks: Task[] = await api.fetchTasks() commit("setTasks", tasks) } }