I am using vue3.As shown in the below posted code, in the class test.js should be a composable class. i want this class to reflect the change of state in another vue-component. in other words, the value of state changes
as eminent in the code, i want to reflect the updated value of state in a vue-component. i want the vue-component to display the different states set in the test.js
to achieve that, i made the state of type ref as shown in the code.
in the vue-component as shonw below, i call and display the contents of state = useState() in ' state: {{state }}' and i expect the states to be displayed are not-satrted,started, processing and successful. But that does not happend.
how can i print updated values of state from test.js in a vue-component please.
vue-component:
<template>
<span> state: {{state }}</span>
</template>
<script>
import { useStates } from '../xxx/xxx/Composables/test.js';
const state = useStates();
test.js
import { ref, onMounted, onUnmounted } from 'vue'
// by convention, composable function names start with "use"
export function useStates() {
let state = ref('not-satrted')
setTimeout(() => {
state.value = 'started'
}, 1000);
setTimeout(() => {
state.value = 'processing'
}, 2000);
setTimeout(() => {
state.value = 'successful'
}, 3000);
// expose managed state as return value
return state
}
vuejs2ANDvuejs3- perhaps that's the issue, the two versions are quite differentdigitizationStatusneeds to be made reactive before you export it if you want the value updated in the .js file to be reflected in the vue component, not after. The .js file should be made into a composable. Or if a store like Pinia makes sense for your app you can just use thatdigitizationStatusvariable from inside a class, there's no way how you can do that heredigitizationStatus =in a sane way, should have been a refmittor any other third-party event emitter or implement pubsub pattern in any other way, so it would be possible to subscribe to events withon()from the outside and emit them withemit()from the inside. There's more than one way to do this, this is just one that is generic and doesn't enforce a class to hack around Vue quirks