How can I use JSON data to populate the options of a q-select ?
-
Please anyone which an example on how to use a json to populate a q-select… or inject json objects into q-select… I’m new to quasar…
-
@thri60 That would depend on where that json is stored. If that is a web link, you can do something like this:
onLoad (response) { console.log(response) } onError (error) { console.log(error) } const oReq = new XMLHttpRequest() oReq.onload = onLoad oReq.onerror = onError oReq.open('get', 'https://domain.com/data.json', true) oReq.send()
if that is inside your project and will be packed:
import json from '/path-to-json/data.json'
or if you need specific values:
import { value1, value2 } from '/path-to-json/data.json'
-
@ilia this was really helped.
I just had to
import location from '/assets/locations.json
then
export default { data() { return { locations: location, } } }
then referenced locations