Vue框架——页面组件中使用小组件

小组件在components文件夹中,页面组件在views文件夹中

一、先写小组件的vue,比如text.vue(在template设置模板渲染,style设置样式)

<template>
  <div class="text">
    <p>tttt</p>
  </div>
</template>

<script>
    export default {
        name: "text"
    }
</script>

<style scoped>
  .text {
    color: red;
  }
</style>

二、页面组件(Home.vue)中使用小组件需要这几步:

1.先导入小组件(import T from '@/components/text')

2.然后在export default中注册小组件

  components:{

    T

  }

3.在template中写: <T></T>    把text.vue的模板传递过来

<template>
  <div class="home">
    <T></T>
  </div>
</template>

<script>
import T from '@/components/text'

export default {
  name: 'home',
  components: {
      T
  }
}
</script>
原文地址:https://www.cnblogs.com/wangcuican/p/11650695.html