提交抓取器后检索值

huangapple go评论91阅读模式
英文:

Retrieving values after submitting fetcher

问题

  1. 我有这个处理程序提交一个获取器
  2. const fetcher = useFetcher();
  3. const handlerLogin = () => {
  4. fetcher.submit({ value: 'social', value1:'second', value3:'third' }, { method: 'POST' });
  5. };
  6. 它正确访问了操作方法路由器6)。 我可以访问第一个数组参数中的所有值如下
  7. export async function action({request, params}){
  8. const formData=Object.fromEntries(await request.formData())
  9. console.log(formData.value1) ---> 打印: second
  10. 如何访问传递在第二个数组中的值`{ method: 'POST' }`
英文:

I have this handler submitting a fetcher

  1. const fetcher = useFetcher();
  2. const handlerLogin = () => {
  3. fetcher.submit({ value: 'social', value1:'second', value3:'third' }, { method: 'POST' });
  4. };

It is accessing the action method properly (router 6). I could access all the values in the first array (parameter) as:

  1. export async function action({request, params}){
  2. const formData=Object.fromEntries(await request.formData())
  3. console.log(formData.value1) ---> prints: second

How could I access the value(s) passed in the second array, i.e. { method: 'POST' }?

答案1

得分: 1

你可以使用点表示法或括号表示法访问方法属性的值,就像这样:

console.log(request.method); // 打印 "POST"

英文:

You can access the value of the method property by using dot notation or bracket notation, like this:

  1. console.log(request.method); // print "POST"

huangapple
  • 本文由 发表于 2023年7月14日 04:35:56
  • 转载请务必保留本文链接:https://go.coder-hub.com/76683078.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定