在 NuxtJS Vue 中设置一个 class 为原型

Set a class to prototype in NuxtJS Vue

如何在 Vue NuxtJS 中正确设置 class 原型?

我创建插件

nuxt.config.js

plugins: [
    { src: "~/plugins/global.js" },
],

global.js

import Vue from "vue";
import CustomStore from "devextreme/data/custom_store";

//try set in prototype
Vue.use(CustomStore)

有错误

A class must be instantiated using the 'new'

我知道这是不正确的,但我找不到任何地方如何初始化它

Vue.use(new CustomStore());

没有报错但是怎么调用?

我想在我的组件中使用这样的东西

this.dataSource = this.$CustomStore({ ///... settings...// })

我假设CustomStore是一个函数,所以你可以尝试使用Nuxt.js inject()方法。此方法将使您的函数或值在您的应用程序中可用。

~/plugins/global.js

export default ({ app }, inject) => {
  // Inject $CustomStore() in Vue, context and store.
  inject('CustomStore', CustomStore)
}

然后您可以在您的应用程序组件中使用它。

你的组件

 mounted() {
   this.$CustomStore()
 },

引用https://nuxtjs.org/docs/2.x/directory-structure/plugins#inject-in-root--context