在 Vue 组件中为 Angular 动态设置属性

Posted

技术标签:

【中文标题】在 Vue 组件中为 Angular 动态设置属性【英文标题】:Set property dynamically in Vue component for angular 【发布时间】:2021-10-29 08:31:02 【问题描述】:

我阅读了这个thread 并创建了网络组件:

<my-vue-web-comp [userId]="1"></my-vue-web-comp>

当我设置静态道具时,它在 Angular 中运行良好。但是当我尝试动态设置属性时:

<my-vue-web-comp [userId]=" usersInfo.userId "></my-vue-web-comp>

我的属性 userId 在 web 组件中为空。看起来 Web 组件是在编译时转换的,而不是在运行时转换的。

我该如何解决这个问题?

【问题讨论】:

【参考方案1】:

我认为在 Angular 中你只能这样做

<my-vue-web-comp [userId]="usersInfo.userId"></my-vue-web-comp>

或者这个

<my-vue-web-comp userId=" usersInfo.userId "></my-vue-web-comp>

如果两者都不起作用,试试这个

<my-vue-web-comp user-id=" usersInfo.userId "></my-vue-web-comp>

【讨论】:

以上是关于在 Vue 组件中为 Angular 动态设置属性的主要内容,如果未能解决你的问题,请参考以下文章