I see the following format of code in Vue.js tutorials a lot and was wondering if it is a javascript object. I'm checking w3schoosl now and it seems javascript objects are defined by a variable instead of having the straight return command followed by the parenthesis. Could someone guide me in the correct direction? Thanks! :) I'm trying to learn the code one by one and sometimes am confused whether something belongs to the framework I'm using or plain javascript. :)
return {
messages: [
{
message: 'Hey!',
user: 'John Doe'
},
{
message: 'Hello!',
user: 'Jane Jennings'
}
]
}
This is a plain javascript object. Returning the way that you did or assigning to a variable produces the same result, it still a javascript object. Directly returning the object is just a shortcut and reduces the amount of code, producing the same results.
Vue is written using javascript so it uses javascript objects too.
You are returning a javascript object with a property called messages
which, in turn, is an array containing several objects, each separated by a comma.
You can tell it's an object because of the { ... }
that encapsulates a group of properties.
// object
{
property: 'value'
}
You can tell that the message
property is an array because of the [ ... ]
that encapsulates a list of items, separate by commas.
message: [
{}, // first object, notice the comma
{} // second object
]
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.