axios中的意外令牌获取请求

时间:2018-09-13 08:13:38

标签: javascript vue.js axios

我是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 | 

这确实令人困惑,因为一切似乎都很正常。感谢您的提示以解决此问题。

1 个答案:

答案 0 :(得分:1)

您在.之后遇到意外的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 => {   })
  }
相关问题