2👍
✅
you should define selected
to Ref.
- let selected = 'A';
+ const selected = ref('A');
now Vue can track selected
change
And you can also use like this.
<component :is="selected === 'A' ? A : B">
0👍
在script中定义的变量应该是一个具有响应式的变量,例如
const selected = ref('A');
或者
const selected = reactive('A');
当然,你需要提前引入ref
或者reactive
。
Source:stackexchange.com