Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Vue 3: global import for ref, reactive and computed

How do I import globally with Vue 3 in the main.js the ref, reactive and computed?

I'm trying to avoid doing this in each component:

import { ref, reactive, computed } from 'vue'
like image 785
Adri HM Avatar asked Dec 29 '25 04:12

Adri HM


1 Answers

Not sure this is a good idea (it likely defeats tree shaking), but it's possible to make them global by adding them to window:

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

window.ref = ref
window.reactive = reactive
window.computed = computed

If using ESLint, make sure to configure these globals:

// eslintrc.js
module.exports = {
  globals: {
    ref: true,
    reactive: true,
    computed: true,
  }
}
like image 178
tony19 Avatar answered Dec 30 '25 17:12

tony19