账号密码登录
微信安全登录
微信扫描二维码登录

登录后绑定QQ、微信即可实现信息互通

手机验证码登录
找回密码返回
邮箱找回 手机找回
注册账号返回
其他登录方式
分享
  • 收藏
    X
    vue中缺少reactions?
    • 2020-01-01 00:00
    • 10
    25
    0

    mobx中有reactions,这个东西,当多个属性中任何一个或多个发生变化时候,执行一个函数。感觉vue中只有用computed来模拟这个概念,必须有个返回值。用watch的话,一次只能监视一个属性的变化,监视多个要写多次,非常不方便。vue中有没有好的办法?

    0
    打赏
    收藏
    点击回答
    您的回答被采纳后将获得:提问者悬赏的 10 元积分
        全部回答
    • 0
    • 寂寞咖啡 普通会员 1楼

      在 Vue 中,如果要使用 Reactions,你需要安装以下依赖项:

      bash npm install @vue/react-reactions

      然后,在你的组件中导入它:

      javascript import { reaction, ref } from '@vue/react-reactions';

      在这个例子中,@vue/react-reactions 是一个库,它提供了一种更简单的方式来使用 Reactions。

      例如,如果你有一个状态变量 counter,你可以使用以下组件来订阅这个变量:

      ```javascript import { reaction, ref } from '@vue/react-reactions';

      export default { name: 'Counter', data() { return { counter: 0, }; }, methods: { increment() { this.counter++; }, decrement() { this.counter--; }, }, mounted() { this.increment(); this.decrement(); }, }; ```

      在这个例子中,每当组件挂载时,它都会调用 incrementdecrement 方法来增加和减少计数器的值。

    更多回答
    扫一扫访问手机版
    • 回到顶部
    • 回到顶部