Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Uncaught ReferenceError: vm is not defined vue.js 2.0

Tags:

vuejs2

I am using Vue 2.0 and I have an error

(Uncaught ReferenceError: vm is not defined)

when i use vm.$data or any other in console to check the properties. I have latest version of vue.js 2.2.4.

like image 557
user3423920 Avatar asked Mar 14 '17 09:03

user3423920


2 Answers

As mentioned by @Fiete the vm variable wont be available by default.

You need to define vm globally to access it from the console.

Something like this should work

var vm = new Vue({
  el: '#app',
  data: {
    a: 1
  },
  router,
  template: '<App/>',
  components: {
    App
  }
});

global.vm = vm; //Define your app variable globally

Now you can use vm.$data.PROPERTY or vm.PROPERTY.

like image 150
Abdullah Khan Avatar answered Nov 10 '22 03:11

Abdullah Khan


The vm variable does not exists by default. And vuejs does not set that variable. If you want to debug your vuejs application I recommend the vuejs Chrome extension.

By opening the extension on your page you can select the component you want to debug. After that you can access the selected component by using the $vm0 variable.

like image 2
Fiete Avatar answered Nov 10 '22 02:11

Fiete