小编R.Q*_*R.Q的帖子

如何在 Vue 3 中使用 Vue.prototype 或全局变量?

Like the title, I want to add Axios into Vue prototype. So when I want to use it, I can use it like this.$axios instead of importing it every time.

CODE:

//plugins/axios.ts

import axios from 'axios'
import router from '../router/index'

const errorHandle = (): void => {};

const instance = axios.create({
  // baseURL: process.env.NODE_ENV == 'development' ? '' : ''
  baseURL: 'http://localhost:3000',
  timeout: 1000 * 12
});

instance.defaults.headers.post['Content-Type'] = 'application/x-www-form-urlencoded;charset=UTF-8'

export default instance
Run Code Online (Sandbox Code Playgroud)
import { createApp } from 'vue'
import …
Run Code Online (Sandbox Code Playgroud)

javascript vue.js axios vuejs3

16
推荐指数
2
解决办法
1万
查看次数

标签 统计

axios ×1

javascript ×1

vue.js ×1

vuejs3 ×1