Browse Source

ensure methods are available in data() (close #4302)

dev
Evan You 8 years ago
parent
commit
6034c3e699
  1. 2
      src/core/instance/state.js
  2. 30
      test/unit/features/options/data.spec.js

2
src/core/instance/state.js

@ -25,9 +25,9 @@ import {
export function initState (vm: Component) {
vm._watchers = []
initProps(vm)
initMethods(vm)
initData(vm)
initComputed(vm)
initMethods(vm)
initWatch(vm)
}

30
test/unit/features/options/data.spec.js

@ -75,4 +75,34 @@ describe('Options data', () => {
vm.$data = {}
expect('Avoid replacing instance root $data').toHaveBeenWarned()
})
it('should have access to props', () => {
const Test = {
props: ['a'],
data () {
return {
b: this.a
}
}
}
const vm = new Vue({
template: `<test ref="test" :a="1"></test>`,
components: { Test }
}).$mount()
expect(vm.$refs.test.b).toBe(1)
})
it('should have access to methods', () => {
const vm = new Vue({
methods: {
get () {
return { a: 1 }
}
},
data () {
return this.get()
}
})
expect(vm.a).toBe(1)
})
})

Loading…
Cancel
Save