-
-
Notifications
You must be signed in to change notification settings - Fork 4.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
asyncData doesn't work when load from static
#1850
Comments
You'll have to either provide the full url: axios.get('http://localhost:3000/data.json') Or load it in the mounted () {
axios.get('/data.json')
.then(({ data }) => {
return { title: data.title }
})
} |
@cretueusebiu if I load it in |
Use the full URL as in the first example. |
@cretueusebiu and conditionally replace url when build? I mean there will be one url in Dev and another in Prod, right? |
Of course, you would use an env variable for the url. And maybe extract the code to a file where you have the api calls. |
If I use asyncData ({ params }) {
return axios.get('http://localhost:3000/data.json')
.then((res) => {
console.log(res)
return { data: res.data }
})
} Then I can't do |
It shouldn't be separate server. I wan't this JSON file inside Nuxt app. |
If you don't want to load it just import it as you do with js files: import data from 'path/to/data' |
I tried that first. Then I can't edit file content. If I edit JSON file it doesn't have any effect to app. |
And this is strange behavior. Because Nuxt is copying JSON file into |
I guess it's because JSON file is from |
I guess you either figured this out by now, or did something else; but I would try putting the file you want in your |
You can add custom watch paths to your nuxt config: build: {
watch: ['path/to/data']
} A change to these files will trigger a rebuild and restart the server. Note that Nuxt path prefixes ( |
Same problem here. But no need for editing json files.
|
I had this working by simply using |
This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs. |
For some reason this doesn't work
How to load data from
static
folder?I have JSON files there, where I want to manage content.
The text was updated successfully, but these errors were encountered: