編寫組件頁面
1.在components下新建一個新建組件頁面,如下所示
2.新建完成之后初始頁面的代碼如下所示:
3.下面從element-ui上找一個頂部導航菜單寫到組件頁面。
<el-menu :default-active="activeIndex2" class="el-menu-demo" mode="horizontal" @select="handleSelect" background-color="#545c64" text-color="#fff" active-text-color="#ffd04b"> <el-menu-item index="1">處理中心</el-menu-item> <el-submenu index="2"> <template slot="title">我的工作台</template> <el-menu-item index="2-1">選項1</el-menu-item> <el-menu-item index="2-2">選項2</el-menu-item> <el-menu-item index="2-3">選項3</el-menu-item> <el-submenu index="2-4"> <template slot="title">選項4</template> <el-menu-item index="2-4-1">選項1</el-menu-item> <el-menu-item index="2-4-2">選項2</el-menu-item> <el-menu-item index="2-4-3">選項3</el-menu-item> </el-submenu> </el-submenu> <el-menu-item index="3" disabled>消息中心</el-menu-item> <el-menu-item index="4"><a href="https://www.ele.me" target="_blank">訂單管理</a></el-menu-item> </el-menu>
使用組件
1.引入組件
import MinorTopMenu from '~/components/MinorTopMenu.vue'
2.注冊組件
components: {
MinorTopMenu
}
3.使用組件
<MinorTopMenu></MinorTopMenu>
4.頁面代碼截圖
測試
打開頁面,如下所示,說明組件使用成功
說明:本文為原創作品,若有參考會在文中提及,如有遺漏,涉及侵權,請聯系本人,將立即修正。