【问题标题】:Vue 3: global import for ref, reactive and computedVue 3:ref、reactive 和 computed 的全局导入
【发布时间】:2020-12-13 10:29:23
【问题描述】:

如何在main.jsrefreactivecomputed 中使用Vue 3 全局导入?

我试图避免在每个组件中这样做:

import { ref, reactive, computed } from 'vue'

【问题讨论】:

    标签: javascript vue.js vuejs3


    【解决方案1】:

    不确定这是一个好主意(它可能会击败摇树),但可以通过将它们添加到 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,
      }
    }
    

    【讨论】:

      猜你喜欢
      • 2021-10-09
      • 2021-10-09
      • 1970-01-01
      • 2021-02-15
      • 2021-07-29
      • 2021-10-18
      • 1970-01-01
      • 2020-06-07
      • 1970-01-01
      相关资源
      最近更新 更多