How do you use the queried GraphQL data in the <script>?
See original GitHub issueI’m using a simple query to fetch the site name:
<static-query>
query {
metaData {
siteName
siteDescription
}
}
</static-query>
I want to set this name as the site title. The default template for site titles is %s - Site Title
, but for this page, I only want to set it to Site Title
. I would like the use the queried data so that I do not have to update it in case I change the value of siteTitle
in module.exports
.
This is what I tried:
<script>
export default {
metaInfo: {
// title: 'Site Title', <--- not using this because it makes the title "Site Title - Site Title"
titleTemplate: static.metaData.siteName
},
}
</script>
But it was giving an error. I also tried putting a $
in front of static
, but it returned undefined. Is it possible to do this?
Issue Analytics
- State:
- Created 4 years ago
- Reactions:1
- Comments:5 (3 by maintainers)
Top Results From Across the Web
How to use GraphQL with Javascript – GraphQL.js tutorial
This is how we can use plain JavaScript to write GraphQL queries with GraphQL.js. Next steps. Serve GraphQL over HTTP with a Server...
Read more >GraphQL | A query language for your API
A query language for your API — GraphQL provides a complete description of the data in your API, gives clients the power to...
Read more >GraphQL - Query - Tutorialspoint
A GraphQL query is used to read or fetch values while a mutation is used to write or post values. In either case,...
Read more >Querying with GraphQL - Postman Learning Center
Postman can make HTTP calls using GraphQL, an open-source data query and manipulation language for APIs, in addition to REST.
Read more >Query record data using the GraphQL API framework
Use the @source directive in your schema script. @defer query directive. Defer processing of a GraphQL fragment until later in the query. Use...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Hi @themindstorm, this is a common sticking point with Vue.
this
is dynamically injected into Vue instances only when the context is evaluated. To have access to “this”, the context needs to be a function. In this case, changingmetaInfo
from an object to a function with a return will fix your issue:@bbugh is there any reason to use the function-less approach? Otherwise I’d update the docs to explain the way to do it with a function.