davestewart / vuex-pathify

Vue / Vuex plugin providing a unified path syntax to Vuex stores
https://davestewart.github.io/vuex-pathify
MIT License
1.37k stars 57 forks source link

Problem using registerModule() #26

Open ArnoBuschmann opened 6 years ago

ArnoBuschmann commented 6 years ago

Hello,

congrats on creating vuex-pathify, I like it a lot! :)

Unfortunately I have a problem in using registerModule() as described in the documentation.

Here is the code, showing, how the 'normal' registerModule method in created works well as expected, but the pathify way by registering it in extend fails. The error message with that is "user is not defined on the instance".

<template>
  <div>
    <p>dynamic store</p>
    <pre>user: {{user}}</pre>
    <el-button @click="showThis()">console log this</el-button>
  </div>
</template>
<script>
import { get, registerModule } from 'vuex-pathify'
import module from './store/user'
const members = function () {
  return {
    // I tried two computed versions seperately, none of them were successful:
    // computed: {
    //   user: get('user')
    // }
    computed: get('user')
  }
}
export default {
  // extend: registerModule('user', module, members), // this doesn't work
  created() {
    this.$store.registerModule("user", module) // this works
  },
  // additional computed properties
  computed: {
    foo () {
      return 'foo'
    },
    user: get('user') // used when registering via created, commented out when trying via extend.
  },
  // additional methods
  methods: {
    showThis () {
      console.log('I want to see this: ', this)
    }
  } 
}
</script>

What should I change to get it working?

davestewart commented 6 years ago

Hmmm. Sorry about that.

I've yet to write tests so this might just be sloppy programming on my side :P

I'll look at this over the weekend - sorry it's not sooner!

ArnoBuschmann commented 6 years ago

Take your time, no hurries :)

davestewart commented 6 years ago

OK, I have some time next week to work on this!

davestewart commented 5 years ago

Just linking another registerModule issue: #74