请求中获取浏览器推荐语言 🔗 1 2 3 4 5 6 7 8 9 10 11 12 let languages: string[] | undefined // get locale from cookie const localeCookie = request.cookies.get('locale') languages = localeCookie?.value ? [localeCookie.value] : [] if (!languages.length) { // Negotiator expects plain object so we need to transform headers const negotiatorHeaders: Record<string, string> = {} request.headers.forEach((value, key) => (negotiatorHeaders[key]
简易的事件监听 🔗 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 const createEvent = () => ({ events: {} as any, on(eventName: string, callback: Function) { this.events[eventName]?.push(callback) || (this.events[eventName] = [callback]); return () => { this.events[eventName] = this.events[eventName].filter( (e: any) => e !== callback ); }; }, emit(eventName: string, ...args: any[]) { const callbacks = this.events[eventName];
日常我们在vue开发的时候使用公共事件总线进行跨组建数据传递,这里我们自己封装一个事件总线,了解其背后的原理 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16