Javascript 在Vue.js中将道具传递给根实例
问题 我试图将一个道具传递给我的根构造函数。我理解Javascript 在Vue.js中将道具传递给根实例,javascript,typescript,vue.js,Javascript,Typescript,Vue.js,问题 我试图将一个道具传递给我的根构造函数。我理解propsData: 这是接收道具的AppComponent: export default class AppComponent extends Vue { @Prop() test: string; mounted() { console.log('test = ' + this.test); // result: test = undefined // expect
propsData
:
这是接收道具的AppComponent
:
export default class AppComponent extends Vue {
@Prop()
test: string;
mounted() {
console.log('test = ' + this.test);
// result: test = undefined
// expected: test = 'hi!'
}
}
我尝试过的事情 使其在开发(而非生产)中发挥作用的唯一方法是: 它在开发(windows)上工作,但在部署(linux)中,我遇到以下类型脚本错误:
ERROR in [at-loader] ClientApp/components/app/app.ts:14:34
TS2339: Property 'test' does not exist on type 'Vue'.
是另一篇关于这一点的帖子。您可以在对象中传递
道具
,这是createElement
别名h
函数在渲染
选项中采用的第二个参数
render: h => h('app', { props: { test: 'hi!' }})
ERROR in [at-loader] ClientApp/components/app/app.ts:14:34
TS2339: Property 'test' does not exist on type 'Vue'.
render: h => h('app', { props: { test: 'hi!' }})