这个新的语法gql`string是什么? [英] What is this new syntax gql`string`
本文介绍了这个新的语法gql`string是什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
const GET_DOGS = gql`
{
dogs {
id
breed
}
}
`;
我从此处找到了这种新语法.
I found this new syntax from here.
您能解释一下这种语法吗?在哪里可以找到有关它的详细信息?
Can you explain this syntax? Where can I find detail about it?
推荐答案
It's called a tagged template. Template literals (`...`
) can be prefixed with a function name. Upon evaluation, this function will be called and the static and dynamic parts of the template literal are passed to the function. Example:
function foo(staticParts, dynamicParts) {
console.log(staticParts, dynamicParts);
}
foo`this is a ${42} test`
带标签的模板可用于创建域特定语言,例如本示例
Tagged templates can be used to create domain specific languages, such as in this example.
关于标签模板,有围绕标签模板的许多问题.
这篇关于这个新的语法gql`string是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文