[Vue warn]: The "data" option should be a function
lvvlan opened this issue · 4 comments
lvvlan commented
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
I'm trying to do this
data () {
return {
testMobx: TestClass
}
}
but warning still exists
kuitos commented
Could you please provide a minimum reproduction with codesandbox? You can make it with this template https://codesandbox.io/s/j76vj84zw9
lvvlan commented
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,