4

In the code below, the getWidth event handler (defined in the methods object) updates the data.width property. As it updates, the variable width should be shown live in VueJS's Chrome addon.

However, that live update doesn't show up in the Vue DevTools. I'm not sure if there is something wrong with the code or what am I doing wrong. The add-on isn't a problem since I've tested in Firefox too.

HTML

<div id="app">
  <p :style="{width: 200 + 'px'}" class="box">{{msg}}</p>
  <button v-on:click="getWidth">New Width</button>
</div>

JS

new Vue({
  el: '#app',
  data: {
    msg: 'Test Message',
    mywidth: ''
  },
  methods: { 
    getWidth: function(){
      this.mywidth = 20 * 2;
    }
  }
})
5
  • Most JS Function calls need () to execute the function. I'm new to Vue as well so not sure if it's needed. But where you have v-on:click="getWidth", what happens if you add the () at the end of getWidth. So v-on:click="getWidth()" Commented Oct 6, 2017 at 13:12
  • @DylanWright () isn't required to execute the method. However if you there's a variable you'd want to pass to the method then you'd pass that using () something as (width). Commented Oct 6, 2017 at 13:16
  • how mywidth is related with width ? Commented Oct 6, 2017 at 13:17
  • @user2486 they aren't related. Commented Oct 6, 2017 at 13:17
  • Well, you are using width in <p> and it appears nowhere else in the supplied code. Commented Oct 6, 2017 at 13:22

1 Answer 1

3

This is happening because you aren't actually using your mywidth data property anywhere.

The Vue DevTools only updates its references to the Vue component's data properties when they are accessed in code, not when they are set.

Simply use that data property somewhere (like putting {{ mywidth }} in the template) and it'll be updated in the Vue DevTools extension.

Sign up to request clarification or add additional context in comments.

1 Comment

@appu This is assuming you mistyped when you say "the variable width should be shown live in VueJS's Chrome addon" and that you meant mywidth. Your component doesn't have a width property defined.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.