Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
4.2k views
in Technique[技术] by (71.8m points)

vue3 中使用axios 报错

我在main中

import { createApp } from 'vue'
import App from './App.vue'
import axios from 'axios'
import VueAxios from 'vue-axios'
import installElementPlus from './plugins/element.js'

const app = createApp(App)
installElementPlus(app)
app.mount('#app')
app.use(VueAxios, axios)

这么生命的,在index.vue中这么使用

  created(){
    this.getData()
  },
  
  methods: {
    
    getData(){
      this.axios.request({url:'http://www.liulongbin.top:3005/api/getlunbo',method:'get'})
      .then(res=>{
        console.log(res.data);
        //this.ArtList = res.data.data;
      })
      
    }
  },

出现错误:

image.png
呢??

修改成:

  created(){
    this.getData()
  },
  
  methods: {
    
    getData(){
      this.axios.get('http://www.liulongbin.top:3005/api/getlunbo')
      .then(res=>{
        console.log(res.data);
        //this.ArtList = res.data.data;
      })
      
    }
  },

结果报错:
image.png

这是什么鬼,求教!!!


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

看下 vue-axios 版本 是否是 3.x

app.use() 放在mount之前


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...