gpt4 book ai didi

vue.js - import axios 导致 vue v3 和 vite 出现问题

转载 作者:行者123 更新时间:2023-12-04 08:12:08 24 4
gpt4 key购买 nike

import axios from 'axios';


导致 vite throw

Uncaught SyntaxError: import not found: default


示例代码
import { createApp } from 'vue';
import TheContainer from './components/TheContainer.vue';
import axios from 'axios';

axios.defaults.baseURL = process.env.VUE_APP_API_URL;

const app = createApp({
components: {
TheContainer
}
})
app.axios = axios;
app.$http = axios;
app.config.globalProperties.axios = axios;
app.config.globalProperties.$http = axios;
app.mount('#app');
这是使用 axios 0.21.1 和 vue 3.0.5
试图找出问题所在... vuejs v3 cookbook 遗憾地通过 cdn 调用 axios 0.14 代码

最佳答案

Redaxios是 axios 的现代翻版。

import axios from 'redaxios';
// use as you would normally
这解决了我对 vite 和 axios 的问题。也适用于 webpack。

关于vue.js - import axios 导致 vue v3 和 vite 出现问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/65900822/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com