Should be enough to do this:
let content;
import axios from 'axios'
axios.get('http://127.0.0.1:8000/api/courses').then(({data}) => content = data)
Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.
ok so I have content.json and I also have a similar structure in a database now, great!
How can I set my variables to get the data from the api?
getting data from the file works fine
import Content from '@/Content.json'
// read in the english version and parse it
const myObjStr = JSON.stringify(Content.en);
const content = JSON.parse(myObjStr);
getting data from API works but don't I have to set the variable content to res.data.en somehow?
import axios from 'axios'
const content = axios.get('http://127.0.0.1:8000/api/courses').then((res) => {
console.log('DATABASE:', res.data);
});
Please or to participate in this conversation.