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数组
```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)
}
结果是这样
这是已经拿到了呀,只是你console.log的是它的代理,所以看到的是proxy
在请求执行成功后执行回调函数中的内容,回调函数处于其它函数的内部this不会与任何对象绑定,为undefined。