mobxjs / mobx-vue

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

视图层不响应,我这样有问题吗? #8

Closed yee94 closed 6 years ago

yee94 commented 6 years ago
<template>
    <div class = "overlook-setting">
        {{testMobx.data}}
    </div>
</template>
<script>
  import { Component, Vue } from 'vue-property-decorator'
  import { observable, action } from 'mobx'

  class TestMobx {
    constructor() {
    }

    @observable data = 9

    @action.bound setData() {
      this.data++
    }
  }

  let TestClass = new TestMobx()

  @Component
  export default class OverlookSetting extends Vue {
    testMobx = TestClass

    mounted() {
      this.testMobx.setData()
      this.testMobx.data++
      console.log(this.testMobx.data)

    }

    beforeDestroy() {
    }

  }
</script>
<style lang = "less" scoped>
    .overlook-setting {
    }
</style>

当我运行上面这段代码的时候打印出来的数据是10 ,但Dom还是9

Vue版本2.5.16 ,Mobx版本4.3.1

yee94 commented 6 years ago

对不起,我的问题。。。没有引入你的库

lvvlan commented 6 years ago

想问下,你用vue-property-decorator这个装饰库,会报 The "data" option should be a function that returns a per-instance value in component definitions. 的warning吗?