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'))
与 worker.start()
类似,你可以将请求处理程序列表作为 worker.use()
方法的参数进行传播。无需多次调用它!
¥Similar to worker.start()
, you can spread a list of request handlers as
arguments to the worker.use()
method. No need to call it multiple times!
只要当前运行时存在,前置的请求处理程序就会一直存在于工作器上(因此,它们通常被称为 “运行时请求处理程序”)。
¥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)