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

Posted wangcuican

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了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>

 

以上是关于Vue框架——页面组件中使用小组件的主要内容,如果未能解决你的问题,请参考以下文章

Vue-CLI项目框架小知识

代码中怎么看出使用了vue框架

vue除了组件还有什么

VS Code中小程序与Vue常用插件合集(前端合集)

vue递归组件的一些理解

Vue系列