Vue引入其他组件的部分内容

Vue引入其他组件的部分内容

在想要引入某一组件内容的页面绑定一个状态值

<template>
    <div>
    <com-main :state="true"></com-main>
    <div>
<template>

<script>
import comMain from '@/views/home/components/index/index.vue'

export default {
    components:{
    'com-main':comMain
  }
}
</script>

在组件中用props接收状态值    此时组件中h2的内容就会被引入上面的页面中

<template>
  <div>
    <h1 v-if="!state">我是麦兜儿</h1>
    <h2>我是麦麦兜兜儿</h2>
  </div>
</template>

<script>
export default {
  props:{
    state:{
      type:Boolean
    }
  }
}
</script>

 

posted @ 2020-07-31 11:46  麦麦兜兜儿  阅读(461)  评论(0编辑  收藏  举报