菜鸟在线求助! 2023-04-15 10:20 采纳率: 46.2%
浏览 63

vue发送axios请求服务器返回值拿不到data值

vue发送axios请求服务器返回值拿不到data值
vue发送axios请求服务器返回值时直接输出Response.data是正确的值,

script>
import pubsub from 'pubsub-js'
import axios from "axios"
export default {
name:"serch",
data(){
    return {
       serchname:"",
       serchtype:"",
       li:[]
    }
},



methods:{
  gget(){
       axios.get('http://localhost:8081/selectall/',{params:{name:this.serchname,type:this.serchtype}}
      
      ).
      then(Response =>{
        

console.log(Response.data)

},
error =>{
console.log(error)

}


输出的值就是正确的json数组

img


但是当将Response.data放入vue里就不行,就拿不到data,


```html

<script>
import pubsub from 'pubsub-js'
import axios from "axios"
export default {
name:"serch",
data(){
    return {
       serchname:"",
       serchtype:"",
       li:[]
    }
},



methods:{
  gget(){
       axios.get('http://localhost:8081/selectall/',{params:{name:this.serchname,type:this.serchtype}}
      
      ).
      then(Response =>{
        

this.li=Response.data
console.log(this.li)
},
error =>{
console.log(error)

}


结果是这样

img

  • 写回答

2条回答 默认 最新

  • 乘风xs 2023-04-15 11:39
    关注

    这是已经拿到了呀,只是你console.log的是它的代理,所以看到的是proxy

    评论

报告相同问题?

问题事件

  • 创建了问题 4月15日