为什么我需要在vue-class-component中声明两次props?

时间:2017-10-27 13:33:59

标签: vue.js vue-component

使用vue-class-component时,我需要在类本身的@Component装饰器 AND 中声明我的道具。它似乎相当多余且容易出错。

这是打算还是我在这里遗漏了什么?

<script lang="ts">
    import Vue from 'vue'
    import Component from 'vue-class-component'

    // Here we declare that score and counter are props
    @Component({
        props: {
            score:Number, 
            counter:Number
        }
    })

    // Now I have to declare score and counter again ?
    // Adding to the confusion is the fact that Typescript types are
    // written differently from Vue types (number vs Number)
    export default class ScoreBar extends Vue {
        score:number
        counter:number
        created(){
            console.log(`score prop is ${this.score} counter is ${this.counter}`)
        }
    }
</script>

0 个答案:

没有答案