update Button

This commit is contained in:
梁灏 2018-07-01 11:33:33 +08:00
parent e7fc76d850
commit f9a6a467a6
2 changed files with 17 additions and 10 deletions

View file

@ -5,7 +5,9 @@
:disabled="disabled" :disabled="disabled"
:href="linkUrl" :href="linkUrl"
:target="target" :target="target"
@click="handleClickLink"> @click.exact="handleClickLink($event, false)"
@click.ctrl="handleClickLink($event, true)"
@click.meta="handleClickLink($event, true)">
<Icon class="ivu-load-loop" type="ios-loading" v-if="loading"></Icon> <Icon class="ivu-load-loop" type="ios-loading" v-if="loading"></Icon>
<Icon :type="icon" :custom="customIcon" v-if="(icon || customIcon) && !loading"></Icon> <Icon :type="icon" :custom="customIcon" v-if="(icon || customIcon) && !loading"></Icon>
<span v-if="showSlot" ref="slot"><slot></slot></span> <span v-if="showSlot" ref="slot"><slot></slot></span>
@ -99,10 +101,11 @@
} }
}, },
methods: { methods: {
handleClickLink (event) { // Ctrl or CMD and click, open in new window when use `to`
handleClickLink (event, new_window) {
this.$emit('click', event); this.$emit('click', event);
this.handleCheckClick(event); this.handleCheckClick(event, new_window);
} }
}, },
mounted () { mounted () {

View file

@ -24,21 +24,25 @@ export default {
} }
}, },
methods: { methods: {
handleClick () { handleClick (new_window = false) {
const isRoute = this.$router; if (new_window){
if (isRoute) { window.open(this.to);
this.replace ? this.$router.replace(this.to) : this.$router.push(this.to);
} else { } else {
window.location.href = this.to; const isRoute = this.$router;
if (isRoute) {
this.replace ? this.$router.replace(this.to) : this.$router.push(this.to);
} else {
window.location.href = this.to;
}
} }
}, },
handleCheckClick (event) { handleCheckClick (event, new_window = false) {
if (this.to) { if (this.to) {
if (this.target === '_blank') { if (this.target === '_blank') {
return false; return false;
} else { } else {
event.preventDefault(); event.preventDefault();
this.handleClick(); this.handleClick(new_window);
} }
} }
} }