Commit 7ff2f71a2f9db26890bdfe5ecdfb06ac907c4d06
1 parent
9d553a2b
fix
修复on-select事件不触发
Showing
2 changed files
with
11 additions
and
9 deletions
Show diff stats
src/components/anchor/anchor-link.vue
| @@ -5,11 +5,9 @@ | @@ -5,11 +5,9 @@ | ||
| 5 | </div> | 5 | </div> |
| 6 | </template> | 6 | </template> |
| 7 | <script> | 7 | <script> |
| 8 | -import mixinsLink from '../../mixins/link'; | ||
| 9 | export default { | 8 | export default { |
| 10 | name: 'AnchorLink', | 9 | name: 'AnchorLink', |
| 11 | inject: ['anchorCom'], | 10 | inject: ['anchorCom'], |
| 12 | - mixins: [ mixinsLink ], | ||
| 13 | props: { | 11 | props: { |
| 14 | href: String, | 12 | href: String, |
| 15 | title: String | 13 | title: String |
| @@ -33,10 +31,15 @@ export default { | @@ -33,10 +31,15 @@ export default { | ||
| 33 | } | 31 | } |
| 34 | }, | 32 | }, |
| 35 | methods: { | 33 | methods: { |
| 36 | - goAnchor (event) { | 34 | + goAnchor () { |
| 37 | this.currentLink = this.href; | 35 | this.currentLink = this.href; |
| 38 | - this.$emit('on-select', this.href); | ||
| 39 | - this.handleCheckClick(event); | 36 | + this.anchorCom.$emit('on-select', this.href); |
| 37 | + const isRoute = this.$router; | ||
| 38 | + if (isRoute) { | ||
| 39 | + this.$router.push(this.href); | ||
| 40 | + } else { | ||
| 41 | + window.location.href = this.href; | ||
| 42 | + } | ||
| 40 | } | 43 | } |
| 41 | }, | 44 | }, |
| 42 | mounted () { | 45 | mounted () { |
src/mixins/link.js
| @@ -26,15 +26,14 @@ export default { | @@ -26,15 +26,14 @@ export default { | ||
| 26 | methods: { | 26 | methods: { |
| 27 | handleClick () { | 27 | handleClick () { |
| 28 | const isRoute = this.$router; | 28 | const isRoute = this.$router; |
| 29 | - const href = this.to || this.href; | ||
| 30 | if (isRoute) { | 29 | if (isRoute) { |
| 31 | - this.replace ? this.$router.replace(href) : this.$router.push(href); | 30 | + this.replace ? this.$router.replace(this.to) : this.$router.push(this.to); |
| 32 | } else { | 31 | } else { |
| 33 | - window.location.href = href; | 32 | + window.location.href = this.to; |
| 34 | } | 33 | } |
| 35 | }, | 34 | }, |
| 36 | handleCheckClick (event) { | 35 | handleCheckClick (event) { |
| 37 | - if (this.to || this.href) { | 36 | + if (this.to) { |
| 38 | if (this.target === '_blank') { | 37 | if (this.target === '_blank') { |
| 39 | return false; | 38 | return false; |
| 40 | } else { | 39 | } else { |