问题描述
如何在Vue 3
,main.js
,ref
和reactive
中与computed
一起全局导入?
我试图避免在每个组件中执行此操作:
import { ref,reactive,computed } from 'vue'
解决方法
不确定这是个好主意(可能会克服摇树的问题),但可以通过将它们添加到window
来使其全局化:
// main.js
import { ref,reactive,computed } from 'vue'
window.ref = ref
window.reactive = reactive
window.computed = computed
如果使用ESLint,请确保配置以下全局变量:
// eslintrc.js
module.exports = {
globals: {
ref: true,reactive: true,computed: true,}
}