在第三方脚本(NUXT ^2.15.3)中使用商店和路线
NUXT上的项目 ^2.15.3。我有一个可以在数据库中执行异步查询的类,我需要导入商店和路由,以便可以在内部使用它们,现在当我在构造函数中初始化类时,我为自己分配了一个路由器和一个商店,但是问题是,当在不同页面上提出请求时,路由器参数不动态,它不会改变,是的,我可以从asyncdata转移存储和路由器,但是这是独立的用途没有商店和路由器的不断转移。
requestMongo.js
export default class {
constructor({ store, $axios, i18n, $config, route }) {
this.api = $axios.create({
baseURL: `${$config.baseURL}/${$config.mongoURL}`,
method: 'post', // default
headers: {
common: {
Accept: "application/json",
}
}
});
this.store = store;
this.i18n = i18n;
this.route = route; - the router is static and does not show changes when you navigate to other pages
}
函数
export default async function ({ store, $axios , i18n , route, $config }, inject) {
const requestMongo = new RequestMongo({ store,$axios,i18n,route,$config });
inject('requestMongo', requestMongo);}
.js nuxt.config.js
plugins: [
{ src: '@/plugins/functions.js' },]
我尝试导入商店,但
import store from '../../store'
但是
import {store} from '../../store'
存储是nes
undefined
是否可以在同类产品中调用实际的商店和路由器而无需求助于
async asyncData({$requestMongo,route,$store}) {
return await $requestMongo.getSingleSlugPage({route,$store})
},
您的时间
project on nuxt ^2.15.3. I have a class that performs asynchronous queries to the database, I need to import the store and route so that I can use them inside, now when I initialize the class in the constructor, I assign myself a router and a store, but the problem is that when making requests on different pages, the router parameter not dynamic, it does not change ,yes i can transfer store and router from asyncData ,but it is the independent use that is of interest without the constant transfer of the store and the router.
requestMongo.js
export default class {
constructor({ store, $axios, i18n, $config, route }) {
this.api = $axios.create({
baseURL: `${$config.baseURL}/${$config.mongoURL}`,
method: 'post', // default
headers: {
common: {
Accept: "application/json",
}
}
});
this.store = store;
this.i18n = i18n;
this.route = route; - the router is static and does not show changes when you navigate to other pages
}
function.js
export default async function ({ store, $axios , i18n , route, $config }, inject) {
const requestMongo = new RequestMongo({ store,$axios,i18n,route,$config });
inject('requestMongo', requestMongo);}
nuxt.config.js
plugins: [
{ src: '@/plugins/functions.js' },]
I tried to import the store but
import store from '../../store'
or
import {store} from '../../store'
But store is undefined
is it possible to call the actual store and router in the class without resorting to
async asyncData({$requestMongo,route,$store}) {
return await $requestMongo.getSingleSlugPage({route,$store})
},
thanks for your time
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论