Evan You 10 лет назад
Родитель
Сommit
56f80aac7a
2 измененных файлов с 25 добавлено и 0 удалено
  1. 10 0
      src/api/global.js
  2. 15 0
      test/unit/specs/api/global_spec.js

+ 10 - 0
src/api/global.js

@@ -105,6 +105,16 @@ exports.use = function (plugin) {
   return this
 }
 
+/**
+ * Apply a global mixin by merging it into the default
+ * options.
+ */
+
+exports.mixin = function (mixin) {
+  var Vue = _.Vue
+  Vue.options = _.mergeOptions(Vue.options, mixin)
+}
+
 /**
  * Create asset registration methods with the following
  * signature:

+ 15 - 0
test/unit/specs/api/global_spec.js

@@ -57,6 +57,21 @@ describe('Global API', function () {
     delete Vue.options.directives['plugin-test']
   })
 
+  it('global mixin', function () {
+    var options = Vue.options
+    var spy = jasmine.createSpy('global mixin')
+    Vue.mixin({
+      created: function () {
+        spy(this.$options.myOption)
+      }
+    })
+    new Vue({
+      myOption: 'hello'
+    })
+    expect(spy).toHaveBeenCalledWith('hello')
+    Vue.options = options
+  })
+
   describe('Asset registration', function () {
 
     var Test = Vue.extend()