R
R
Ruslan Absalyamov2018-11-24 20:32:33
Vue.js
Ruslan Absalyamov, 2018-11-24 20:32:33

How to populate data all through axios in created lifecycle?

I have a problem that while the life cycle I use like this

beforeCreate: function () {
            let transaction = new RestApi('transaction.json');
            transaction.list().then(res => {
                this.accounts = res.data.accounts;
                this.transactions = res.data.transactions;
            });
        },

Then the data in this.accounts will be filled in when I checked the beforeUpdate life cycle in the console and that is why I have such errors
Error in render: "TypeError: Cannot read property 'toString' of undefined"

Although everything is rendered normally, but in the console there is such an error.
Here is my sandbox. in file /src/App.vue https://codesandbox.io/s/qzmr6lp01j

Answer the question

In order to leave comments, you need to log in

1 answer(s)
0
0xD34F, 2018-11-24
@rusline18

Set null as initial values ​​for accounts and transactions. In the template, you add v-if="accounts"to v-if="transactions"those blocks inside which elements are rendered based on the corresponding properties.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question