Skip to content

Commit

Permalink
merge Allow dynamic values in v-link #9
Browse files Browse the repository at this point in the history
  • Loading branch information
yyx990803 committed Jun 7, 2015
2 parents 0ed4540 + 6e92388 commit 0338b63
Showing 1 changed file with 11 additions and 6 deletions.
17 changes: 11 additions & 6 deletions src/link.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,21 +5,26 @@ module.exports = function (Vue) {

Vue.directive('link', {

isLiteral: true,

bind: function () {
var vm = this.vm
var href = this.expression
if (this.el.tagName === 'A') {
this.el.href = href
}
var self = this
this.handler = function (e) {
e.preventDefault()
vm.route._router.go(href)
self.vm.$root.route._router.go(self.destination)
}
this.el.addEventListener('click', this.handler)
},

unbind: function () {
this.el.removeEventListener('click', this.handler)
},

update: function (value) {
this.destination = value
if (this.el.tagName === 'A') {
this.el.href = value
}
}

})
Expand Down

0 comments on commit 0338b63

Please sign in to comment.