提交抓取器后检索值

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

Retrieving values after submitting fetcher

问题

我有这个处理程序提交一个获取器

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

它正确访问了操作方法路由器6)。 我可以访问第一个数组参数中的所有值如下

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

如何访问传递在第二个数组中的值`{ method: 'POST' }`
英文:

I have this handler submitting a fetcher

const fetcher = useFetcher();

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

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

export async function action({request, params}){
    const formData=Object.fromEntries(await request.formData())
	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:

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:

确定