Vue 中的 ts

作者: shuaiutopia | 来源:发表于2020-06-29 13:52 被阅读0次

vue-property-decorator 中的 @Wathch

属性值必须在定义时有初始化值, 否则 watch 不生效

<script lang='ts'>  
import { Vue, Component, Watch} from 'vue-property-decorator'

@Component
export default Class Deom extends Vue {
    private testData: number = 1 // 这里必须有初始化值,否则 watch 不生效
    @Watch('testData')
    onTestDataChange() {
        console.log('testData新值', this.testData)
    }
    
    created() {
        this.testData = Math.random()
    }
}

相关文章

网友评论

    本文标题:Vue 中的 ts

    本文链接:https://www.haomeiwen.com/subject/dbuofktx.html