当模板引用变量放置在模态中时(因此最初未定义),我无法使用 ViewChildren 访问模板引用变量。即使在将模态插入到 DOM 中之后,元素的 QueryList 的长度仍然为零。
这里的最小可重现示例: https ://stackblitz.com/edit/angular-whsdr6
对于上面的示例,我希望 console.log 返回一个对象,其结果属性是长度为 5 的数组(五个段落标记元素)。
以下组件:
<template lang="html">
<div>
<p>{{ bar }}</p>
</div>
</template>
<script lang="ts">
import Vue from 'vue';
export const FooBar = Vue.extend({
computed: {
bar: function() {
return this.foo;
}
},
data: function() {
return {
foo: 'bar',
};
},
});
export default FooBar;
</script>
Run Code Online (Sandbox Code Playgroud)
导致类型错误:
13:19 Property 'foo' does not exist on type 'CombinedVueInstance<Vue, unknown, unknown, unknown, Readonly<Record<never, any>>>'.
11 | computed: {
12 | bar: function() {
> 13 | return this.foo;
| ^
14 | }
15 | }, …Run Code Online (Sandbox Code Playgroud)