Vue 3 and Vuex 4 - Dialog header and content templates can't access vuex state

With Vue 2 and Vuex 3 we could add store property to template in order to access vuex state with "this.$store" but this approach doesn't work anymore because instead of...

Vue.component(...)

we now have to use...

const app = createApp();

...to use "app.component(...)" when setting up template. But now it's new app instance and it'doesn't have access to store. I couldn't get store to work even when using...

import {useStore} from '..store';
const app = createApp();
app.use(store);

... or when I try to access this inside template with setup block...

setup() {
  const store = useStore();
return {
someVariable: computed(() => store.state.someVariable),
} }

So how can I access vuex state inside templates across Syncfusion controls? ... with Vue 3 and Vuex 4. If I can make it work for Dialog it would work everywhere :)


6 Replies

BS Buvana Sathasivam Syncfusion Team February 16, 2022 06:26 PM UTC

Hi Janno, 

Currently, we are validating your reported query. We will update you with further details on or before February 21, 2022. 

Regards, 
Buvana S 



VJ Vinitha Jeyakumar Syncfusion Team February 25, 2022 11:53 AM UTC

Hi Janno,


Your reported issue can be resolved by adding the Dialog's content using custom component where we can access the vuex state. please check the code below,

Code snippet:
App.vue
<template>
  <div>
    <div class="col-lg-12 control-section">
        <!-- Render Button to open the Dialog -->
        <ejs-button id='dlgbtn' v-if="OpenBtn" @click.native="BtnClick">Open</ejs-button>

        <ejs-dialog :buttons='dlgButtons' ref="dialogObj"  :header='headerTemplate'  :animationSettings='animationSettings'  showCloseIcon=true :target='target' width='500px' :open="dialogOpen"
            :close="dialogClose">
       <base-container title="Vuex">
    <change-counter></change-counter>
  </base-container>
        </ejs-dialog>
    </div>
  </div>
</template>
<script>
methods: {
    addOne() {
      // Variant I, with action
      this.$store.dispatch("increase", { value: 10 });

      // Variant II, with mutation
      this.$store.commit({
        type: "increase",
        value: 10,
      });
    },
</script>
BaseContainer.vue
<template>
  <section>
    <h2>{{ title }}</h2>
    <h1>Direct Storage {{ $store.state.counter }}</h1>
    <slot></slot>
  </section>
</template>

<script>
export default {
  props: ["title"],
};
</script>
ChangeCounter.vue
<template>
  <button @click="increment">Add 2 (Increment Action)</button>
  <button @click="increase({ value: 10 })">Add 10 (Increase Action)</button>
</template>

<script>
import { mapActions } from "vuex";

export default {
  methods: {
    ...mapActions(["increment", "increase"]),

  },
};
</script>




Regards,
Vinitha



JL Janno Liivak August 29, 2022 07:17 PM UTC

Sadly this doesn't help me very much. How can I access Vuex store state from templates? ... specifically from Dialog's header, content and footer template. How must I define dialog's header template in order it to access vuex store to which dialog it'self has access?

header template is defined as such:

const app = createApp();
const headerTemplate = app.component('headerTemplate', {
  template: ....,
  
data: () => ({}),
});


VJ Vinitha Jeyakumar Syncfusion Team August 30, 2022 03:25 PM UTC

Hi Janno,


Currently, we are validating your reported query. we will update you the further details on or before 2nd September 2022.

Regards,
Vinitha


VJ Vinitha Jeyakumar Syncfusion Team September 5, 2022 01:54 PM UTC

Hi Janno,


Still, we are validating your reported query due to its complexity. we will update you the further details on or before 8th September 2022.

Regards,
Vinitha




VJ Vinitha Jeyakumar Syncfusion Team September 15, 2022 01:27 PM UTC

Hi Janno,

Sorry for the inconvenience caused

Can you please explain the issue which you are facing with the sample we have provided using custom component. It will be helpful for us to further validate on the issue.

Please share us with the issue reproducing code snippet or sample.

Regards,
Vinitha

Loader.
Up arrow icon