Skip to content

Commit 6e92388

Browse files
committed
Allow dynamic values in v-link
1 parent dad31b5 commit 6e92388

File tree

2 files changed

+10
-7
lines changed

2 files changed

+10
-7
lines changed

src/index.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@ p.start = function (vm) {
131131
return
132132
}
133133
this._started = true
134-
this._vm = this._vm || vm
134+
this._vm = this._vm || vm.$root
135135
if (!this._vm) {
136136
throw new Error(
137137
'vue-router must be started with a root Vue instance.'

src/link.js

+9-6
Original file line numberDiff line numberDiff line change
@@ -6,20 +6,23 @@ module.exports = function (Vue) {
66
Vue.directive('link', {
77

88
bind: function () {
9-
var vm = this.vm
10-
var href = this.expression
11-
if (this.el.tagName === 'A') {
12-
this.el.href = href
13-
}
9+
var self = this
1410
this.handler = function (e) {
1511
e.preventDefault()
16-
vm.route._router.go(href)
12+
self.vm.$root.route._router.go(self.destination)
1713
}
1814
this.el.addEventListener('click', this.handler)
1915
},
2016

2117
unbind: function () {
2218
this.el.removeEventListener('click', this.handler)
19+
},
20+
21+
update: function (value) {
22+
this.destination = value
23+
if (this.el.tagName === 'A') {
24+
this.el.href = value
25+
}
2326
}
2427

2528
})

0 commit comments

Comments
 (0)