vue.jsvuex2-way-object-databindingvuex-orm

Two way data binding with Vuex-ORM


Does anybody know of a library or an already described pattern for achieving two way data binding in forms when using Vuex ORM?

I've found a couple of libraries for helping with this with Vuex, but none specifically for Vuex-ORM yet:


Solution

  • I don't think there is any predefined plugin to do this, but you should be able to do the same for typical Vuex states using setter and getter on computed property...?

    import User from '@/models/User'
    
    export default {
      computed: {
        user: {
          get () {
            return User.find(1)
          },
    
          set (value) {
            User.update({
              where: 1,
              data: {
                name: value
              }
            })
          }
        }
      }
    }