[英]vuejs3 : can't import axios globally
I can import and use axios in a component:我可以在组件中导入和使用 axios:
import axios from 'axios'
export default function usePostLogin() {
const login = async (url , data , callback) => {
axios.post(url, data)
// etc
I want to import axios globally.我想全局导入 axios。
In main.js :在 main.js 中:
import axios from 'axios'
const app = createApp(App)
app.component('FontAwesome', FontAwesomeIcon)
app.use(createPinia()).use(router).use(axios)
app.mount('#app')
But then I get an error : error 'axios' is not defined no-undef
但后来我得到一个错误:
error 'axios' is not defined no-undef
You can not add axios with use
in Vue3, in main.js add it to the global property:您不能在 Vue3 中
use
添加 axios,在 main.js 中将其添加到全局属性中:
app.config.globalProperties.axios = axios
and in component use it like:并在组件中使用它:
this.axios
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.