在vue的項目開發過程中,基本都是基於組件化開發項目,總結下使用組件的幾個點:
一、@符號的使用
在vue項目中 @ 符號代表的是根目錄,即 src 目錄。
二、組件的放置位置
在項目中,公用的組件放置在 components 目錄下,項目組件新建 views 目錄來存放:
三、組件的引和使用方法
1、第一種引入和使用方法:
import navs from '@/views/nav/index'
使用組件:
components:{ 'v-nav':navs }
模板中使用組件:
<v-nav></v-nav>
2、第二種引入和使用方法
import navs from '@/views/nav/index' import indexList from './index-list'
使用組件:
components: { navs,indexList },
模板中使用:
<index-list></index-list> <navs></navs>
3、第三種使用方法
組件目錄:
引入方式:
import BackToTop from '@/components/BackToTop'
使用組件:
components: { BackToTop },
使用組件:
<el-tooltip placement="top" content="tooltip"> <back-to-top :custom-style="myBackToTopStyle" :visibility-height="300" :back-position="50" transition-name="fade" /> </el-tooltip>
其實沒什么,只是要注意下組件大小寫命名的寫法。