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>

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM