首页 > 其他 > 详细

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

时间:2019-10-10 23:14:52      阅读:138      评论:0      收藏:0      [点我收藏+]

小组件在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框架——页面组件中使用小组件

原文:https://www.cnblogs.com/wangcuican/p/11650695.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!