【发布时间】:2019-06-11 17:31:36
【问题描述】:
我似乎无法弄清楚使用 Typescript 和类组件库将数组作为道具传递给 Vue 中的组件的正确方法。 Following the official template,我尝试了以下操作:
<script lang="ts">
import { Component, Vue} from 'vue-property-decorator';
const AppProps = Vue.extend({
props: {
propsMessage: String,
},
});
@Component({})
export default class Table extends AppProps {
mounted() {
console.log(this.propsMessage);
}
}
</script>
在一些模板中包含这个:
<template>
<Table :propsMessage="['This', 'is', 'Bob']" />
</template>
确实有效,并给出以下输出:
[“这个”、“是”、“鲍勃”]
这是我想要的,但这肯定不是将数组作为道具传递的正确方法?我什至没有将propsMessage 定义为String[]。做了一些研究,我发现this article 提到有一个与此问题相关的bug。此问题已得到修复,并且一直是 merged just recently。所以,现在应该有办法做到这一点,但我找不到任何关于如何正确做到这一点的文档。
【问题讨论】:
标签: typescript class vue.js components