Skip to content

Commit

Permalink
perf: rewrite to declarative, close #64
Browse files Browse the repository at this point in the history
  • Loading branch information
Scrum committed May 18, 2020
1 parent 19ac9f0 commit 6f8a4ff
Showing 1 changed file with 47 additions and 1 deletion.
48 changes: 47 additions & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import {ComponentOptions, PluginObject, VueConstructor} from 'vue'
import {ComponentOptions, PluginObject, VueConstructor, VNode} from 'vue'
import { Route } from 'vue-router';

type CallbackFunction = (params: any) => string;
Expand Down Expand Up @@ -32,6 +32,52 @@ class VueBreadcrumbs implements PluginObject<ComponentOptions<Vue>> {
return path;
}
},
render(createElement): VNode {
if (this.$breadcrumbs.length) {
return createElement(
'ol',
{
class: {
'breadcrumb': true
}
},
this.$breadcrumbs.map((crumb: Route, index: number) => {
if (crumb && crumb.meta && crumb.meta.breadcrumb) {
return createElement(
'li',
{
class: {
'breadcrumb-item': true
},
props: {
key: index
}
},
[
createElement(
'router-link',
{
attrs: {
'active-class': 'active'
},
props: {
to: { path: this.getPath(crumb) },
tag: index !== this.$breadcrumbs.length - 1 ? 'a' : 'span'
}
},
` ${this.getBreadcrumb(crumb.meta.breadcrumb)}`
)
]
)
}

return createElement();
})
)
}

return createElement();
},
template: `
<ol
class="breadcrumb"
Expand Down

0 comments on commit 6f8a4ff

Please sign in to comment.