0
点赞
收藏
分享

微信扫一扫

[vue]全局配置

素锦时年_1b00 2022-04-15 阅读 84
vue.js

方法1

目前网上的全局设置大部分都是设置

app.config.globalProperties.$axios= instance

然后再setup()中

import { getCurrentInstance } from "vue";
{ctx}=getCurrentInstance();
ctx.$axios

但是该方法存在一个问题就是ctx也是是vue2中的this,在本地正常,线上会有意想不到的问题

方法2

const app = Vue.createApp({});
app.provide('http', http);

然后在setup()中

import { defineComponent, ref, reactive, onMounted, toRefs, inject } from "vue";
const http = inject("http");
举报

相关推荐

0 条评论