小编Mig*_*ger的帖子

如何反应性地使用计算属性中元素的宽度

我试图根据组件中元素的宽度设置计算属性。问题是我不知道如何以反应性的方式获取宽度。

我的元素上有一个 ref 来获取有效的宽度。但是我似乎无法让 vue 检测到宽度正在变化

我将元素设置为:

<div ref="myDiv"></div>
Run Code Online (Sandbox Code Playgroud)

我的计算属性为:

myProperty() {
  return this.$refs.myDiv.clientWidth/2;
}
Run Code Online (Sandbox Code Playgroud)

myProperty 计算正确,但不会随着 myDiv 宽度的变化而变化

vue.js

5
推荐指数
1
解决办法
5764
查看次数

如何从打字稿中访问mat菜单触发器

我有以下html:

<button mat-icon-button #notificationMenuBtn [matMenuTriggerFor]="notificationsMenu">
</button>
<mat-menu #notificationsMenu="matMenu" [overlapTrigger]="false">
</mat-menu>
Run Code Online (Sandbox Code Playgroud)

如何从typescript上访问notificaitonMenuBtn上的thematMenuTriggerFor?我尝试使用View Child(如下所示),但我似乎无法将其绑定到触发器,仅绑定到按钮.

@ViewChild('notificationMenuBtn') notificationMenuBtn : MatMenuTrigger;
this.notificationMenuBtn.openMenu();
Run Code Online (Sandbox Code Playgroud)

typescript material-design angular

4
推荐指数
2
解决办法
6865
查看次数

标签 统计

angular ×1

material-design ×1

typescript ×1

vue.js ×1