]> git.ipfire.org Git - thirdparty/vuejs/core.git/commitdiff
fix(runtime-core): pass options to plugins (#561)
author宋铄运 <fnlctrl@gmail.com>
Tue, 24 Dec 2019 15:33:47 +0000 (23:33 +0800)
committerEvan You <yyx990803@gmail.com>
Tue, 24 Dec 2019 15:33:47 +0000 (10:33 -0500)
packages/runtime-core/__tests__/apiApp.spec.ts
packages/runtime-core/src/apiCreateApp.ts

index acc25606d7f50abd59dfca832ff229f437a8122d..2a70350cf2aeeb5c3cc5654ab8ac937edd64703e 100644 (file)
@@ -242,13 +242,13 @@ describe('api: createApp', () => {
   test('use', () => {
     const PluginA: Plugin = app => app.provide('foo', 1)
     const PluginB: Plugin = {
-      install: app => app.provide('bar', 2)
+      install: (app, arg1, arg2) => app.provide('bar', arg1 + arg2)
     }
     const PluginC: any = undefined
 
     const app = createApp()
     app.use(PluginA)
-    app.use(PluginB)
+    app.use(PluginB, 1, 1)
 
     const Root = {
       setup() {
index 57d77332a3f91d124fe986c09a06933ea00e7db3..ce0a2371550768c5898dcc600f4297b26d69213c 100644 (file)
@@ -10,7 +10,7 @@ import { createVNode, cloneVNode } from './vnode'
 
 export interface App<HostElement = any> {
   config: AppConfig
-  use(plugin: Plugin, options?: any): this
+  use(plugin: Plugin, ...options: any[]): this
   mixin(mixin: ComponentOptions): this
   component(name: string): Component | undefined
   component(name: string, component: Component): this
@@ -50,7 +50,7 @@ export interface AppContext {
   reload?: () => void // HMR only
 }
 
-type PluginInstallFunction = (app: App) => any
+type PluginInstallFunction = (app: App, ...options: any[]) => any
 
 export type Plugin =
   | PluginInstallFunction
@@ -97,15 +97,15 @@ export function createAppAPI<HostNode, HostElement>(
         }
       },
 
-      use(plugin: Plugin) {
+      use(plugin: Plugin, ...options: any[]) {
         if (installedPlugins.has(plugin)) {
           __DEV__ && warn(`Plugin has already been applied to target app.`)
         } else if (isFunction(plugin)) {
           installedPlugins.add(plugin)
-          plugin(app)
+          plugin(app, ...options)
         } else if (plugin && isFunction(plugin.install)) {
           installedPlugins.add(plugin)
-          plugin.install(app)
+          plugin.install(app, ...options)
         } else if (__DEV__) {
           warn(
             `A plugin must either be a function or an object with an "install" ` +