ABOUT ME

-

Today
-
Yesterday
-
Total
-
  • [Vue] Class Component
    JavaScript/Vue 2020. 11. 6. 15:04
    728x90

    Class Component

    • @Component decorator 사용하면 클래스 컴포넌트 사용 가능
    import Vue from 'vue'
    import Component from 'vue-class-component'
    
    @Component
    export default class ExampleClass extends Vue { }

     

    • data는 클래스의 property로 선언 가능
    import Vue from 'vue'
    import Component from 'vue-class-component'
    @Component
    export default class ExampleClass extends Vue {
        private exampleData: string = 'example';
    }

     

    • method는 클래스의 function으로 선언 가능
    @Component
    export default class ExampleClass extends Vue {
        private exampleMethod(): string {
            return 'Example Method';
        }
    }

     

    • Computed property는 클래스의 getter/setter로 선언 가능
    @Component
    export default class ExampleClass extends Vue {
        private name: string = "Example";
    
        get name() {
            return this.name;
        }
    
        set name(name: string) {
            this.name = name;
        }
    }

     

     

     

    728x90

    'JavaScript > Vue' 카테고리의 다른 글

    [Vue] Vuelidate object property에 validation 적용 방법  (0) 2020.12.21
    [Vue] Vue Apollo GraphQL Authorization(Nest.js)  (0) 2020.12.04
    [Vue] Property Decorator  (0) 2020.11.07
    [Vue] Vue CLI  (0) 2020.09.12
    [Vue] Directive  (0) 2020.09.06
Designed by Tistory.