As I start learning vue.js, I am facing some challenges. I need to implement a dictionary analog in JavaScript, known as a map. However, I'm unsure of where to define it. The map should be utilized in both the checkDevices()
method and within the HTML code.
P.S. Please excuse any language errors in my English
export default {
data: () => ({
}),
devicesList: new Map(
"varNameOne", false,
"varNameTwo", false,
"varNameThree", false,
),
methods: {
async checkDevices () {
let response = await axios.get(`/some/api`)
console.log("res.data: ", response.data);
devicesList.forEach((values, keys) => {
console.log("Key: ", keys, "Value: ", values);
})
}
}
}
I have attempted to define it before export default
like this: let devicesList = new Map(...);
, but unfortunately, it did not work as expected.
When using axios.get(`/some/api`)
, I receive a server response with data (response.data):
device1: true
device2: false
device3: true
I need to extract this data from the response in key-value pairs for UI presentation such as:
- device1 connected
- device2 disconnected
- device3 connected