bananaappletw bananaappletw -4 years ago 157
Javascript Question

Confused about vuejs-templates webpack-simple code snippet

I am a newbie of javascript.

Start to learn Vue.js by reading the examples.

But I am confused about the code snippet of vuejs-templates/webpack-simple.

From line 25

data () {
return {
msg: 'Welcome to Your Vue.js App'
}
}


I am wondering why code can't be written like this

data: () => {
return {
msg: 'Welcome to Your Vue.js App'
}
}


I have tried both code, the same result.

I can't understand from reading Vue.js document.

Please help me to understand this code snippet.

Thank you for taking time reading my problem.

Answer Source

The question is not about why it isn't, but more about why should it.

In both cases, you are defining a function, which is member of an object literal. In es6 there is the feature of method properties, which is used as a shorthand notation. See also MDN.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download