import { ref, computed } from 'nuxt-composition-api'
const state = ref(false)
export default function useColoration() {
const toggle = () => (state.value = !state.value)
return {
state: computed(() => state.value),
toggle
}
}
Se puede lograr un estado compartido globalmente entre los componentes manteniendo la variable state
fuera de la función exportada y devolviendo las propiedades computed
.
import useColoration from '~/use/coloration'
export default {
setup() {
const { state: colorationState, toggle: colorationToggle } = useColoration()
return { colorationState, colorationToggle }
}
}