实例 Vue 使用带有 is 属性和三元表达式的 >component> 元素来切换哪个组件应该处于活动状态

x
 
<template>
  <h1>Dynamic Components</h1>
  <p>Refresh the page and there is a chance the dynamic component will toggle.</p>
  <component :is="Math.random() > 0.5 ? 'comp-one' : 'comp-two'"></component>
</template>
<style>
  #app {
    width: 350px;
    margin: 10px;
  }
  #app > div {
    border: solid black 2px;
    padding: 10px;
    margin-top: 10px;
  }
</style>                  

输出结果