How to access data from computed property Vue.js How to access data from computed property Vue.js node.js node.js

How to access data from computed property Vue.js


This is a very common "gotcha".

Do not use a fat arrow when defining your computed.

When you use a fat arrow to define your computed, methods, or data, you capture this lexically and it will point to the containing scope (which is often window or undefined) and not your Vue.

<script> export default {   name: 'app',   data() {     return {       lang: 'sp'     }   },   computed: {     langEn(){return this.lang === 'en'},     langSp(){return this.lang === 'sp'}   } }</script>