[Vue @Component] Define Props on a Vue Class with vue-property-decorator

While traditional Vue components require a data function which returns an object and a method object with your handlers, vue-class-componentflattens component development by allowing you to add your data properties and handlers directly as properties of your class.

 

Install:

npm i --save vue-class-component vue-property-decorator

 

jsonfing.json:

{
    "compilerOptions": {
        "experimentalDecorators": true
    }
}

 

HelloWorld.vue:

<template>
  <div @click="onClick" class="hello">
    {{message}}
  </div>
</template>

<script>

import {Component, Prop, Vue} from 'vue-property-decorator'

@Component({})
export default class HelloWorld extends Vue {
  @Prop({
    default: 'Default message from Hello World Component'
  })
  message

  onClick() {
    this.message = 'Goodbye'
  }
}
</script>

 

posted @ 2018-07-22 17:53  Zhentiw  阅读(1148)  评论(0编辑  收藏  举报