Vue3+typescript+axios在main.ts中导入封装的axios文件http.ts,在App.vue中使用时报main.ts:9 Uncaught TypeError: Cannot set properties of undefined (setting '$http'),直接在App.vue中导入http.ts是对的
```typescript
main.ts中代码:
import './assets/main.css'
import ElementPlus from 'element-plus'
import 'element-plus/dist/index.css'
import { createApp } from 'vue'
import App from './App.vue'
import http from './assets/http'
const app = createApp(App)
app.use(ElementPlus)
app.config.globalproperties.$http = http;
app.mount('#app')
App.vue中使用
import { ref } from 'vue'
// import $http from './assets/http'
const userForm = ref({
"userno":'',
"username":'',
"pawd":''
})
const subLogin= ()=> {
this.$http.post('pub/json',{"websrvinfo":{"cmdtype":"req"}}).then(response => {
console.log(response);
}).catch(error => {
console.error(error);
});
}
tsconfig.json中的compilerOptions下的"types": ["axios"]已设置
```