File tree Expand file tree Collapse file tree 2 files changed +15
-1
lines changed Expand file tree Collapse file tree 2 files changed +15
-1
lines changed Original file line number Diff line number Diff line change @@ -11,6 +11,7 @@ import {
11
11
query ,
12
12
hasOwn ,
13
13
isReserved ,
14
+ isPlainObject ,
14
15
bind
15
16
} from '../../util/index'
16
17
@@ -76,7 +77,13 @@ export default function (Vue) {
76
77
77
78
Vue . prototype . _initData = function ( ) {
78
79
var dataFn = this . $options . data
79
- var data = this . _data = dataFn ? dataFn ( ) || { } : { }
80
+ var data = this . _data = dataFn ? dataFn ( ) : { }
81
+ if ( ! isPlainObject ( data ) ) {
82
+ data = { }
83
+ process . env . NODE_ENV !== 'production' && warn (
84
+ 'data functions should return an object.'
85
+ )
86
+ }
80
87
var props = this . _props
81
88
var runtimeData = this . _runtimeData
82
89
? typeof this . _runtimeData === 'function'
Original file line number Diff line number Diff line change @@ -2,6 +2,13 @@ var Vue = require('src')
2
2
var _ = require ( 'src/util' )
3
3
4
4
describe ( 'Instance state initialization' , function ( ) {
5
+ it ( 'should warn data functions that do not return an object' , function ( ) {
6
+ new Vue ( {
7
+ data : function ( ) { }
8
+ } )
9
+ expect ( 'should return an object' ) . toHaveBeenWarned ( )
10
+ } )
11
+
5
12
describe ( 'data proxy' , function ( ) {
6
13
var data = {
7
14
a : 0 ,
You can’t perform that action at this time.
0 commit comments