Git Product home page Git Product logo

Comments (9)

michaelolof avatar michaelolof commented on May 29, 2024

Yes you're right.
The current version of vuex-class-component doesn't support Nuxt.
I am actually just reading up on nuxt myself.

from vuex-class-component.

michaelolof avatar michaelolof commented on May 29, 2024

I have modified the ExtractVuexModule function to take one extra parameter target: "core" | "nuxt" it is "core" by default.

If you want to use with nuxt simply use the api like this.

{
  modules: {
    user: UserStore.ExtractVuexModule( UserStore, "nuxt" ),
  }
}

Please do test this in your nuxt apps and give feedback on how well it works so I can add it to the official docs.

Thank you.

from vuex-class-component.

torarnek avatar torarnek commented on May 29, 2024

Hello, and thanks for your quick response. However I could not get this to work. I get Unexpected token export with webpack:/external "vuex-class-component":1:.

The following syntax is deprecated and will be removed in the next version of nuxt:

{
  modules: {
    user: UserStore.ExtractVuexModule( UserStore, "nuxt" ),
  }
}

Ideally it should work as a module. Every file in /store becomes a module.

It would have been great if it could as a normal module-file(e.g. /store/counter.ts) like this:

import { action, getter, Module, mutation, VuexModule } from 'vuex-class-component'

@Module({ namespacedPath: 'counter/' })
class CounterStore extends VuexModule {
  @getter value = 4

  @mutation increaseValue() {
    this.value++
  }

  @action()
  delayedDecrease(wait: number) {
    return new Promise<number>(resolve => {
      setTimeout(() => {
        resolve(this.value--)
      }, wait)
    })
  }
}

export default CounterStore.ExtractVuexModule( CounterStore, "nuxt" )

from vuex-class-component.

asmadsen avatar asmadsen commented on May 29, 2024

You can export the extracted module like you describe. However you would want to export the class as well, since you need the class to create the proxy or else you'll lose most of the benefits.

import { action, getter, Module, mutation, VuexModule } from 'vuex-class-component'

@Module({ namespacedPath: 'counter/' })
export class CounterStore extends VuexModule {
  @getter value = 4

  @mutation increaseValue() {
    this.value++
  }

  @action()
  delayedDecrease(wait: number) {
    return new Promise<number>(resolve => {
      setTimeout(() => {
        resolve(this.value--)
      }, wait)
    })
  }
}

export default CounterStore.ExtractVuexModule( CounterStore, "nuxt" )
<script lang="ts">
import { Component, Vue } from 'vue-property-decorator'
import { CounterStore } from '../store/counter'

@Component
export class SomeComponent extends Vue {
  counter = CounterStore.CreateProxy(this.$store, CounterStore)
  
  get count() {
    return counter.value
  }
}
</script>

from vuex-class-component.

torarnek avatar torarnek commented on May 29, 2024

Did you get this to work with nuxt? Having CounterStore as the only module e.g /store/counter.ts

I still get Unexpected token export.

from vuex-class-component.

asmadsen avatar asmadsen commented on May 29, 2024

I've got it to work by changing the module type to CommonJS, so when the pull request #16 is approved it should work or you could test it out by running npm i --save-dev https://github.com/asmadsen/vuex-class-component.git or yarn add -D https://github.com/asmadsen/vuex-class-component.git

from vuex-class-component.

michaelolof avatar michaelolof commented on May 29, 2024

Hello @torarnek, @asmadsen. Thanks so much for your help.

I have some concerns about this line: f7d31a1#diff-e5e546dd2eb0351f813d63d1b39dbc48R5

While it may solve the problem of nuxt support, it makes the library unusable for pure JavaScript projects.

You end up with a exports is not defined Reference Error. Something like this.

Uncaught ReferenceError: exports is not defined
    at eval (index.js:8)
    at Module.../dist/index.js (app.js:828)
    at __webpack_require__ (app.js:724)
    at fn (app.js:101)
    at eval (user.vuex.js:17)
    at Module../src/vuex/user.vuex.js (app.js:4009)
    at __webpack_require__ (app.js:724)
    at fn (app.js:101)
    at eval (store.js?c0d6:1)
    at Module../src/store.js (app.js:3997)

This is why the newer versions of the library uses es2015 module instead of commonjs

Thoughts?

from vuex-class-component.

michaelolof avatar michaelolof commented on May 29, 2024

Hello guys.

I've made some changes to the codebase and the readme.

You can upgrade now and try it out.

from vuex-class-component.

torarnek avatar torarnek commented on May 29, 2024

Hello, I can confirm that it works with nuxt. Thank you very much this fix.

from vuex-class-component.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.