老师我这里用this.$request报错,我应该怎么修改呢?

来源:2-10 axios二次封装(下)

慕运维1161037

2022-02-18

login.vue:15 Uncaught (in promise) TypeError: this.$request is not a function
at Proxy.mounted (login.vue:15:10)
at callWithErrorHandling (runtime-core.esm-bundler.js:155:22)
at callWithAsyncErrorHandling (runtime-core.esm-bundler.js:164:21)
at Array.hook.__weh.hook.__weh (runtime-core.esm-bundler.js:2667:29)
at flushPostFlushCbs (runtime-core.esm-bundler.js:356:32)
at flushJobs (runtime-core.esm-bundler.js:401:9)

写回答

2回答

河畔一角

2022-02-25

这是Vue3要先挂载到全局对象上,我们课程讲的是通过app.config.globalProperties来挂载的,使用的时候要用proxy.$request,你看下源码和视频

1
0

慕粉3946981

2022-03-01

import {getCurrentInstance} from 'vue'
const globalProperties = getCurrentInstance().appContext.config.globalProperties 
globalProperties.$request


0
1
河畔一角
getCurrentInstance方法会解构一个proxy对象
2022-03-01
共1条回复

Vue3+ElementPlus+Koa2 全栈开发后台系统

从前端晋级到全栈,让你的未来发展有更多可能

1069 学习 · 580 问题

查看课程