Vue: v1.0.18 - Cannot convert undefined or null to object

Created on 21 Mar 2016  路  2Comments  路  Source: vuejs/vue

Hi there!

After and upgrade to latest version v1.0.18 I getting an
Uncaught TypeError: Cannot convert undefined or null to object

I did a roll back to v1.0.17 - and it works well.

Chrome devtools says that error is on var keys = Object.keys(data); line:

/**
       * Initialize the data.
       */

      Vue.prototype._initData = function () {
        var dataFn = this.$options.data;
        var data = this._data = dataFn ? dataFn() : {};
        var props = this._props;
        var runtimeData = this._runtimeData ? typeof this._runtimeData === 'function' ? this._runtimeData() : this._runtimeData : null;
        // proxy data on instance
        var keys = Object.keys(data);
        var i, key;
        i = keys.length;
        while (i--) {
          key = keys[i];
          // there are two scenarios where we can proxy a data key:
          // 1. it's not already defined as a prop
          // 2. it's provided via a instantiation option AND there are no
          //    template prop present
          if (!props || !hasOwn(props, key) || runtimeData && hasOwn(runtimeData, key) && props[key].raw === null) {
            this._proxy(key);
          } else if (process.env.NODE_ENV !== 'production') {
            warn('Data field "' + key + '" is already defined ' + 'as a prop. Use prop default value instead.');
          }
        }
        // observe data
        observe(data, this);
      };

Here is a screenshot of the console: http://prntscr.com/ai19zx

Thank you!

Most helpful comment

It looks like some of your data functions do not return, or return null.

This was already fixed and will land in the next release: https://github.com/vuejs/vue/commit/b80ae34b9c58f1a3979008b03512c8dd70d94952. In the mean time you can keep using 1.0.17 or make sure your data functions return an object.

All 2 comments

Can you paste the data attribute of your component options?

It looks like some of your data functions do not return, or return null.

This was already fixed and will land in the next release: https://github.com/vuejs/vue/commit/b80ae34b9c58f1a3979008b03512c8dd70d94952. In the mean time you can keep using 1.0.17 or make sure your data functions return an object.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

Jokcy picture Jokcy  路  3Comments

loki0609 picture loki0609  路  3Comments

paceband picture paceband  路  3Comments

hiendv picture hiendv  路  3Comments

seemsindie picture seemsindie  路  3Comments