我是vue.js的新手,并尝试使用axios进行GET调用,但收到错误:
<script>
import axios from 'axios';
export default {
name: 'AboutMe',
data () {
return {
profile: {},
}
},
computed: {
token () {
return this.$store.getters.getToken;
},
BASE_URL () {
return this.$store.state.BASE_URL;
},
userid () {
return this.$store.getters.getUserid;
},
},
created: {
axios.get(this.BASE_URL + "/profile/aboutme/" + this.userid )
.then( res => {
console.log.(res.data);
})
.catch( error => { });
}
}
</script>
但是我得到了这个令人讨厌的错误:
SyntaxError: /home/me/vue-myapp/src/components/AboutMe.vue: Unexpected token, expected "," (121:9)
119 |
120 | created: {
> 121 | axios.get(this.BASE_URL + "/profile/aboutme/" + this.userid )
| ^
122 | .then( res => {
123 | console.log.(res.data);
124 |
这真的令人困惑,因为一切看起来都很正常。感谢您的提示以解决此问题。
在.
之后你有一个意外的console.log.(res.data);
。它应该是console.log(res.data);
该物体也是畸形的。应该是这样的:
created: {
axios.get(this.BASE_URL + "/profile/aboutme/" + this.userid )
.then( res => {
console.log.(res.data);
})
.catch( error => { })
}