如何在 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()
},
添加回答
举报
0/150
提交
取消