1

I am trying to display the variable "stage" in the "{{ stageTest }} but I cannot seem to get it working. How do I go about displaying the variable with .vue? I have an alert box working so I know I am getting the result I just cant display it for some reason with .vue any help would be greatly appreciated.

<div>{{ stageTest }}</div>
test() {
  CONTRACT.name1(function (err, res) {
    var stage = res;
    alert(stage);
    this.stageTest = stage;
  })
}
2
  • you defined stageTest in your component's data option? Commented Aug 16, 2018 at 10:08
  • yes i did like this right export default { data () { return { stageTest: null } }, Commented Aug 16, 2018 at 10:19

1 Answer 1

1

This is probably due to the fact that when using the callback function with the function keyword you unbind what this refers to.

test() {
  CONTRACT.name1((err, res) => { // Arrow functions unbind `this`
    var stage = res;
    alert(stage);
    this.stageTest = stage;
  })
}

I replaced your function with an arrow function, which unbinds the this keyword, so you still have the this from the upper scope.

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

Comments

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.