fix(vue-app): add type definition for ComponentOptions.middleware (#4531)

This commit is contained in:
Hartmut 2018-12-14 02:31:25 +00:00 committed by Pooya Parsa
parent b413bc14fb
commit da0a3794ef
3 changed files with 16 additions and 4 deletions

View File

@ -30,6 +30,8 @@ export interface Context {
beforeNuxtRender(fn: (params: { Components: VueRouter['getMatchedComponents'], nuxtState: NuxtState }) => void): void beforeNuxtRender(fn: (params: { Components: VueRouter['getMatchedComponents'], nuxtState: NuxtState }) => void): void
} }
export type Middleware = string | ((ctx: Context, cb: Function) => Promise<void> | void)
export interface Transition { export interface Transition {
name?: string; name?: string;
mode?: string; mode?: string;

View File

@ -5,7 +5,7 @@
import Vue, { ComponentOptions } from "vue"; import Vue, { ComponentOptions } from "vue";
import { Route } from "vue-router"; import { Route } from "vue-router";
import { MetaInfo } from "vue-meta"; import { MetaInfo } from "vue-meta";
import { Context, Transition, LoadingObject } from "./index"; import { Context, Middleware, Transition, LoadingObject } from "./index";
declare module "vue/types/options" { declare module "vue/types/options" {
interface ComponentOptions<V extends Vue> { interface ComponentOptions<V extends Vue> {
@ -14,7 +14,7 @@ declare module "vue/types/options" {
head?: MetaInfo | (() => MetaInfo); head?: MetaInfo | (() => MetaInfo);
key?: string | ((to: Route) => string); key?: string | ((to: Route) => string);
layout?: string | ((ctx: Context) => string); layout?: string | ((ctx: Context) => string);
middleware?: string | string[]; middleware?: Middleware | Middleware[];
scrollToTop?: boolean; scrollToTop?: boolean;
transition?: string | Transition | ((to: Route, from: Route) => string); transition?: string | Transition | ((to: Route, from: Route) => string);
validate?(ctx: Context): Promise<boolean> | boolean; validate?(ctx: Context): Promise<boolean> | boolean;

View File

@ -50,8 +50,18 @@ options.layout = (context) => 'foo'
// middleware // middleware
options.middleware = 'foo' const middlewares: types.Middleware[] = [
options.middleware = ['foo', 'bar'] 'foo',
(ctx) => {},
(ctx, cb) => {},
async (ctx) => {},
async (ctx, cb) => {} // unlikely
]
options.middleware = middlewares
options.middleware = middlewares[0]
options.middleware = middlewares[1]
options.middleware = middlewares[2]
// scrollToTop // scrollToTop