vue3中模块导出为什么一直报错?

这个是request.js文件

import { baseUrl, apiPath } from '@/config/config';

export default {

config:{

baseURL: baseUrl+apiPath,

// 响应拦截器

beforeRequest() {

return new Promise((resolve, reject) => {

console.log('响应拦截器')

resolve('123456')

})

},

// 请求拦截器

handleResponse() {}

},

// request 请求

request(){

return this.config.beforeRequest().then(opt => {

console.log(opt)

})

}

}

这个是entrepot.js文件

import request from '@/request/index.js';

export default {

getEntrepotByKeyword: (params) =>

request({

url: 'activity/groupon/myGroupons',

method: 'GET',

data: params

}),

//意见反馈

feedback: (data) => {

console.log(11111);

}

};

当我调用getEntrepotByKeyworda时,报错:request is not a function。如何解决?


回答:

import { request } from '@/request/index.js'; 

2022-05-20

感谢 @zangeci 的指正,默认导出不可以通过 import 解构。

import request from '@/request/index.js';

const requestInstance = request.request;

export default {

getEntrepotByKeyword: params =>

requestInstance({

url: "activity/groupon/myGroupons",

method: "GET",

data: params,

}),

//意见反馈

feedback: data => {

console.log(11111);

},

};

import { baseUrl, apiPath } from '@/config/config';

export default {

config: {

baseURL: baseUrl+apiPath,

// 响应拦截器

beforeRequest() {

return new Promise((resolve, reject) => {

console.log("响应拦截器");

resolve("123456");

});

},

// 请求拦截器

handleResponse() {},

},

// request 请求

request(options) {

console.log("request -> options:", options);

return this.config.beforeRequest().then(opt => {

console.log(opt);

});

},

};


回答:

request是对象中的一个方法啊,你又不是export default request

以上是 vue3中模块导出为什么一直报错? 的全部内容, 来源链接: utcz.com/p/934318.html

回到顶部