mobxjs / mobx-vue

🐉 Vue bindings for MobX
MIT License
475 stars 22 forks source link

[Vue warn]: The "data" option should be a function #14

Closed lvvlan closed 6 years ago

lvvlan commented 6 years ago

This is my code


<template>
    <div class="test">
        <p>{{testMobx.data}}</p>
    </div>
</template>

<script lang="ts">
import Vue from 'vue'
import Component from 'vue-class-component'
import { Observer } from 'mobx-vue'
import { observable } from 'mobx'

class TestMobx {
    @observable data = 123
}

let TestClass = new TestMobx()

@Observer
@Component
export default class App extends Vue {
    testMobx = TestClass
}
</script>

but has this warning:

[Vue warn]: The "data" option should be a function that returns a per-instance value in component definitions.

why??

lvvlan commented 6 years ago

I'm trying to do this


data () {
    return {
        testMobx: TestClass
    }
}

but warning still exists

kuitos commented 6 years ago

Could you please provide a minimum reproduction with codesandbox? You can make it with this template https://codesandbox.io/s/j76vj84zw9

lvvlan commented 6 years ago

This is a simple demo https://codesandbox.io/s/lj3l95m09 If I use vue-router, this warning will appear, If I not use vue-router, there's no problem,

kuitos commented 6 years ago

@lvvlan fixed and released v2.0.7 Thanks for your feedback!