BoldDesk®Customer service software offering ticketing, live chat, and omnichannel support, starting at $49/mo. for 10 agents. Try it for free.
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 :)
<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> |
<template>
<section>
<h2>{{ title }}</h2>
<h1>Direct Storage {{ $store.state.counter }}</h1>
<slot></slot>
</section>
</template>
<script>
export default {
props: ["title"],
}; </script> |
<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> |
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: () => ({}),
});