main.js中有写: app.config.globalProperties.$http = axios
// vue2 的写法
methods: {
async project_list () {
const { data: res } = await this.$http.get('project_list')
this.data = res
},
现在我要换成 vue3.0 写法,把上面的代码写到setup(){}中去, vue3.0 没有this,具体怎么写,请改代码,多谢
getCurrentInstance 方法不行,getCurrentInstance 方法好象只用在开发环境中
哈喽,我之前有回答过的哦,注意,不要用ctx,用proxy,线上才不会报错。
const { proxy } = getCurrentInstance()
在main.js中写:app.provide("globalProperties", app.config.globalProperties);
在组件中调用:
import { inject } from "vue";
const gp = inject('globalProperties');
gp.$http.get()....