Skip to content

Commit 56f80aa

Browse files
committed
global api: add mixin method
1 parent 9fc0068 commit 56f80aa

File tree

2 files changed

+25
-0
lines changed

2 files changed

+25
-0
lines changed

src/api/global.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,16 @@ exports.use = function (plugin) {
105105
return this
106106
}
107107

108+
/**
109+
* Apply a global mixin by merging it into the default
110+
* options.
111+
*/
112+
113+
exports.mixin = function (mixin) {
114+
var Vue = _.Vue
115+
Vue.options = _.mergeOptions(Vue.options, mixin)
116+
}
117+
108118
/**
109119
* Create asset registration methods with the following
110120
* signature:

test/unit/specs/api/global_spec.js

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,21 @@ describe('Global API', function () {
5757
delete Vue.options.directives['plugin-test']
5858
})
5959

60+
it('global mixin', function () {
61+
var options = Vue.options
62+
var spy = jasmine.createSpy('global mixin')
63+
Vue.mixin({
64+
created: function () {
65+
spy(this.$options.myOption)
66+
}
67+
})
68+
new Vue({
69+
myOption: 'hello'
70+
})
71+
expect(spy).toHaveBeenCalledWith('hello')
72+
Vue.options = options
73+
})
74+
6075
describe('Asset registration', function () {
6176

6277
var Test = Vue.extend()

0 commit comments

Comments
 (0)