iview/src/components/breadcrumb/breadcrumb-item.vue

62 lines
1.7 KiB
Vue
Raw Normal View History

2016-09-09 14:29:19 +08:00
<template>
<span>
2017-11-07 17:28:20 +08:00
<a v-if="to || href" :class="linkClasses" @click="handleClick">
2016-09-09 14:29:19 +08:00
<slot></slot>
</a>
<span v-else :class="linkClasses">
<slot></slot>
</span>
<span :class="separatorClasses" v-html="separator" v-if="!showSeparator"></span>
2017-03-03 21:05:30 +08:00
<span :class="separatorClasses" v-else>
<slot name="separator"></slot>
2016-09-09 14:29:19 +08:00
</span>
</span>
</template>
<script>
2017-11-07 17:28:20 +08:00
// todo 3.0 时废弃 href
2016-09-09 14:29:19 +08:00
const prefixCls = 'ivu-breadcrumb-item';
export default {
name: 'BreadcrumbItem',
2016-09-09 14:29:19 +08:00
props: {
href: {
2017-11-07 17:28:20 +08:00
type: [Object, String]
},
to: {
type: [Object, String]
},
replace: {
type: Boolean,
default: false
2016-09-09 14:29:19 +08:00
}
},
2017-03-03 21:05:30 +08:00
data () {
return {
separator: '',
showSeparator: false
};
2017-03-03 21:05:30 +08:00
},
2016-09-09 14:29:19 +08:00
computed: {
linkClasses () {
return `${prefixCls}-link`;
},
separatorClasses () {
return `${prefixCls}-separator`;
}
},
mounted () {
this.showSeparator = this.$slots.separator !== undefined;
},
methods: {
handleClick () {
const isRoute = this.$router;
if (isRoute) {
2017-11-07 17:28:20 +08:00
this.replace ? this.$router.replace(this.to || this.href) : this.$router.push(this.to || this.href);
} else {
2017-11-07 17:28:20 +08:00
window.location.href = this.to || this.href;
}
}
2016-09-09 14:29:19 +08:00
}
2016-12-25 22:49:42 +08:00
};
</script>