微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

javascript-Vue.js打字稿界面不起作用

有谁知道在vue.js中创建数据属性类型的语法是什么(应用程序是用打字稿编写的)?
我正在寻找类似的东西:

@Component({
  data() {
    return {
      sections: Array<SomeInterface> = []
    }
  }
})

但是vue将类型视为值,而我对如何使用它感到困惑.

解决方法:

您应该将class-style components与vue-class-component一起使用,这样可以将这些声明移至类属性并与Typescript配合使用.

import Vue from 'vue'
import Component from 'vue-class-component'

// The @Component decorator indicates the class is a Vue component
@Component({
  // All component options are allowed in here
  template: '<button @click="onClick">Click!</button>'
})
export default class MyComponent extends Vue {
  // Initial data can be declared as instance properties
  message: string = 'Hello!'

  // Component methods can be declared as instance methods
  onClick (): void {
    window.alert(this.message)
  }
}

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 [email protected] 举报,一经查实,本站将立刻删除。

相关推荐