반응형
Notice
Recent Posts
Recent Comments
Link
| 일 | 월 | 화 | 수 | 목 | 금 | 토 |
|---|---|---|---|---|---|---|
| 1 | 2 | 3 | 4 | 5 | 6 | 7 |
| 8 | 9 | 10 | 11 | 12 | 13 | 14 |
| 15 | 16 | 17 | 18 | 19 | 20 | 21 |
| 22 | 23 | 24 | 25 | 26 | 27 | 28 |
Tags
- Javascript
- 쿠팡학용품
- DI
- webpack
- 의존성주입
- 환급금많이받는법
- 가성비학용품
- 2026AI도구
- 2026종소세
- 자기계발
- 인생꿀팁
- 추천
- HTTP란
- enum
- 새학기꿀템
- Vue+Typescript
- 자바스크립트
- TCP/IP
- ECMAScript
- 인체원소
- 타입스크립트
- vue store
- 실천방법
- 새학기쇼핑
- 2026꿀템
- 중학교준비물
- 유아식기추천 #이유식식기 #흡착식판 #아기빨대컵 #교정젓가락 #이유식스푼 #아기턱받이 #유아도시락 #이유식준비물 #육아템추천 #아기용품추천 #쿠팡추천 #육아맘필수템
- frontend
- 대학생준비물
- TypeScript
Archives
- Today
- Total
끄적끄적
[VUE] Vue+Typescript - Class based component 본문
반응형

Vue + Typescript로 개발할때 Class based component에 유용한 라이브러리들에 대해 소개해보고자 합니다.
개인적으로 타입스크립트기반의 뷰를 만들때 필수적으로 사용하고 있는 라이브러리들입니다.
vue-decorator-property(https://github.com/kaorun343/vue-property-decorator)
vue-class-component기반에 라이브러리로 클래스 컴포넌트 스타일로 개발하기 쉽게 도와주는 데코레이터입니다.
Setup
npm i -S vue-property-decorator
Example
@Component
export class MyComponent extends Vue {
@Prop() age!: number;
@PropSync('name', { type: String }) syncedName!: string;
@Model('change', { type: Boolean }) readonly checked!: boolean;
@ModelSync('checked', 'change', { type: Boolean });
@Watch('child')
onChildChanged(val: string, oldVal: string) {};
@Inject({ from: 'optional', default: 'default' }) readonly optional!: string;
@ProvideReactive() one = 'value';
@Emit('reset')
resetCount() {
this.count = 0
}
}
vuex-class(https://github.com/ktsn/vuex-class)
vuex상태관리를 vue-class-component기반에 데코레이터 방식으로 개발을 할 수 있게 도와줍니다.
Setup
$ npm install --save vuex-class
# or
$ yarn add vuex-class
Example
import Vue from 'vue'
import Component from 'vue-class-component'
import {
State,
Getter,
Action,
Mutation,
namespace
} from 'vuex-class'
const someModule = namespace('path/to/module')
@Component
export class MyComp extends Vue {
@State('foo') stateFoo
@State(state => state.bar) stateBar
@Getter('foo') getterFoo
@Action('foo') actionFoo
@Mutation('foo') mutationFoo
@someModule.Getter('foo') moduleGetterFoo
// If the argument is omitted, use the property name
// for each state/getter/action/mutation type
@State foo
@Getter bar
@Action baz
@Mutation qux
created () {
this.stateFoo // -> store.state.foo
this.stateBar // -> store.state.bar
this.getterFoo // -> store.getters.foo
this.actionFoo({ value: true }) // -> store.dispatch('foo', { value: true })
this.mutationFoo({ value: true }) // -> store.commit('foo', { value: true })
this.moduleGetterFoo // -> store.getters['path/to/module/foo']
}
}
개인적으로 위의 두 라이브러리를 사용하게 되면 클래스 컴포넌트 스타일을 통한 개발에 유용하고 가독성 측면에서도 좀 더 좋은 것 같습니다.
아래에 좀 유익한 자료 몇가지 첨부해 두니 참고하시면 좋을 듯 합니다.
참고자료
https://ui.toast.com/weekly-pick/ko_20190327
https://github.com/vuejs/vue-class-component
http://ccambo.github.io/Dev/Vue/6.How-to-use-vue-property-decorator/
반응형
'Front-end > Vue.js' 카테고리의 다른 글
| [VUE+TYPESCRIPT] Vuex 타입스크립환경 스토어 아키텍처 정리 (0) | 2021.10.29 |
|---|---|
| [VUE] vue-sfc-rollup로 npm 패키지 만들기 (0) | 2021.06.25 |
| [VUE] vuex? store? 무엇일까? 왜 사용할까? (0) | 2020.04.19 |
| [Vue] vue cli를 이용해서 세팅하기 (0) | 2019.11.06 |
| Vue.js란? (0) | 2019.06.01 |
Comments
