mobxjs/mobx-vue

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

lvvlan opened this issue · 4 comments

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??

I'm trying to do this

data () {
    return {
        testMobx: TestClass
    }
}

but warning still exists

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

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,

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