基于 iview Tabs 組件實現
功能:為每個 tab 動態創建不同的、特定的組件內容,而不需要大量的 import 組件并進行 component 注冊
Index.vue
<template> <div class="content-left-menu"> <div class="item-contain layout-content"> <Tabs class="cmcc-ivu-tab2" type="card" closable> <TabPane v-for="k in zj" :label="k.label" > <loader :vueName="k.vueName"></loader> </TabPane> </Tabs> </div> </div></template><script>
import loader from './EntryLoader.vue' export default { components: {loader}, data() { return { zj:[ {label:'tab1',vueName:'workflow/Index'}, {label:'tab2',vueName:'workflow/Index2'}, {label:'tab3',vueName:'workflow/Index3'} ] } } }</script>EntryLoader.vue<script> export default { props: ['vueName'], data() { return {} }, created() { this.$options.components[this.vueName] = require('@/components/' + this.vueName + '.vue') }, render: function (createElement) { return createElement(this.vueName) } }</script>總結
以上所述是小編給大家介紹的vue 動態加載并注冊組件且通過 render動態創建該組件,希望對大家有所幫助,如果大家有任何疑問請給我留言,小編會及時回復大家的。在此也非常感謝大家對錯新站長站網站的支持!
如果你覺得本文對你有幫助,歡迎轉載,煩請注明出處,謝謝!
新聞熱點
疑難解答
圖片精選