vue中:is的用法,動態顯示需要的元件

MayDo發表於2018-12-19

//這個是子元件
<template>
   <div class=feedback>
      <component :is="comps"></component>
   </div>
</template>

<script>
  import caseback from './caseback'
  import comment from './comment'
  import feedback from './feedback'

  export default {
    components: {caseback, comment, feedback},
    props: {
      type: Number  //父元件根據type的值決定顯示哪個元件
     },
    computed: {
      comps() {
          return ['caseback', 'comment', 'feedback'][this.type]
       }
     }
  }
</script>複製程式碼



相關文章