use()

将请求处理程序添加到当前工作实例的前面。

调用签名

¥Call signature

import { http } from 'msw'
import { worker } from './mocks/browser'
 
// Prepend a list of new handlers to this worker instance.
// Past this point, they extend the network behavior.
worker.use(http.get('/resource'), http.post('/resource'))

只要当前运行时存在,前置的请求处理程序就会一直存在于工作器上(因此,它们通常被称为 “运行时请求处理程序”)。

¥The prepended request handlers persist on the worker as long as the current runtime exists (thus, they are often referred to as “runtime request handlers”).

相关材料

¥Related materials

  • 运行时请求处理程序(新 docs/basics/request-handler#runtime-request-handlers 部分的一部分)

    ¥Runtime request handlers (part of a new docs/basics/request-handler#runtime-request-handlers section)

  • 网络行为覆盖

    ¥Network behavior overrides