1

I am using push() method to add data to an object and receiving an Error:

Uncaught (in promise) TypeError: this.message.push is not a function

Some data is received from an API call, which is to be added to the object.

var price = new Vue({
        delimiters: ["[[","]]"],
        el: '#app',
        data: {
            message: {}
    },
    mounted () {
    {% for i in arr %}
        axios
        .get('https:apicall/symbol={{ x }}')
        .then(response => (this.message.push({name : response.data.price , cost: response.data.price.regularMarketPrice.fmt}))
    {% endfor %}
  }
})

However when I changed:

message: []

and

.then(response => (this.message.push(response.data.price))

it worked fine.

I am using Vue in Django framework and am new to Vue.js

1 Answer 1

2

push is an array method not an object method, an array could be initialized as message:[] and an object like message:{}, so you could push a data to an array or assign that data to an object or a property inside that object like :

this.message=response.data.price

or

this.message.price=response.data.price
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.