为了账号安全,请及时绑定邮箱和手机立即绑定

在 NuxtJS Vue 中将类设置为原型

在 NuxtJS Vue 中将类设置为原型

慕姐4208626 2023-08-10 16:03:03
如何在 Vue NuxtJS 中正确设置类原型?我创建插件nuxt.config.jsplugins: [    { src: "~/plugins/global.js" },],全局.jsimport Vue from "vue";import CustomStore from "devextreme/data/custom_store";//try set in prototypeVue.use(CustomStore)有错误A class must be instantiated using the 'new'我知道这是不正确的,但我找不到任何地方如何初始化它Vue.use(new CustomStore());没有错误但是怎么调用呢?我想在我的组件中使用类似的东西this.dataSource = this.$CustomStore({ ///... settings...// })
查看完整描述

1 回答

?
小唯快跑啊

TA贡献1863条经验 获得超2个赞

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


〜/插件/global.js


export default ({ app }, inject) => {

  // Inject $CustomStore() in Vue, context and store.

  inject('CustomStore', CustomStore)

}

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


你的组件


 mounted() {

   this.$CustomStore()

 },

查看完整回答
反对 回复 2023-08-10
  • 1 回答
  • 0 关注
  • 102 浏览
慕课专栏
更多

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信