Vue 3: easy custom global store with computed properties

Alex Zerling
1 min readJan 20, 2021

In Vue 2 I used a global component which has been attached to the Vue object via “Vue.prototype”.

In Vue 3 there is another approach:

//store.js
import { reactive, computed } from 'vue'

const store = {
debug: true,

state: reactive({
message: 'Hello!',
val: 1,
message2: computed(() => store.state.val + 1),
})

--

--