Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/vue.js/6.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Typescript Vue组件道具上的阵列类型会打断门楣_Typescript_Vue.js_Tslint - Fatal编程技术网

Typescript Vue组件道具上的阵列类型会打断门楣

Typescript Vue组件道具上的阵列类型会打断门楣,typescript,vue.js,tslint,Typescript,Vue.js,Tslint,我正在使用Vue.extend创建一个带有数组道具的AppProps类 import Vue from 'vue'; import Component from 'vue-class-component'; const AppProps = Vue.extend({ props: { test1: String, test2: Array, }, }); 然后扩展AppProps来创建我的组件 @Component({}) export default class A

我正在使用Vue.extend创建一个带有数组道具的AppProps类

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

const AppProps = Vue.extend({
  props: {
    test1: String,
    test2: Array,
  },
});
然后扩展AppProps来创建我的组件

@Component({})
export default class ArrayPropsExample extends AppProps {
  get computedMessage() {
    return this.test1 + ' ' + this.test2;
  }
}
这是根据vue类组件中的typescript示例执行的。Vue很高兴,但linter抱怨说在课堂上看不到我的道具类型

19:17类型“ArrayPropsExample”上不存在属性“test1”。 17 |导出默认类ArrayPropsExample扩展AppProps{ 18 |获取computedMessage(){

19 |返回this.test1+“”+this.test2; | ^ 20 | } 21 |}

相关代码在这里()

如果我将test2类型设置为String,那么linter是满意的,但是使用Array似乎会破坏linter。。这是非常奇怪和不一致的

好吧,所以我可以通过改变我的方法来解决这个问题。实际上,在我的Tconfig中引入vue属性装饰器并设置script=false

import Vue from 'vue';
import Component from 'vue-class-component';
import { Prop } from 'vue-property-decorator';

@Component
export default class ArrayPropsExample extends Vue {
  @Prop({ default: 'hello' })
  public test1: string;

  @Prop({ default: []})
  public test2: any[];

  get computedMessage() {
    return this.test1 + ' ' + this.test2;
  }
}
无论如何,我更喜欢这种方法