<nuxt-link>
and some code using the to attribute did not make sense, so I would like to ask you a question.
Below is the nuxt-link.
Bind the to attribute and pass the to (argument 1, argument 2).
<nuxt-link:to="to(id,id2)">
<!-- What's in the link-->
</nuxt-link>
to(){
return(id1:string, id2:string)=>({
name: "slug1-slugId1-slug2-slugId2",
params: {
slugId1,
slugId2
}
});
},
I'm not sure what the function definition of to (argument 1, argument 2) says.
Below is what I understand.
What I don't understand is how to write the Arrow function.
My understanding of Arrow function is
(argument 1, argument 2) = > {
// Handling of something
}
I thought I would write like this, but
Now
(argument 1, argument 2) = >({
name: "slug1-slugId1-slug2-slugId2",
params: {
slugId1,
slugId2
}
})
It says like and I don't understand the existence of ( ) right behind the arrow.
Why is this written like this?
javascript typescript nuxt.js
Short syntax for omitting return
in the Arrow function.If ()
is not present, it is parsed as a sentence column.
The following myFunc1
and myFunc2
provide the same return value.
const myFunc1=(slugId1:string, slugId2:string)=>({
name: "slug1-slugId1-slug2-slugId2",
params: {
slugId1,
slugId2,
},
});
const myFunc2=(slugId1:string, slugId2:string)=>{
US>return{
name: "slug1-slugId1-slug2-slugId2",
params: {
slugId1,
slugId2,
},
};
};
© 2024 OneMinuteCode. All rights reserved.