Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/ssh/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript “中的意外异步操作”;";Vue.js中的axios_Javascript_Vue.js_Axios - Fatal编程技术网

Javascript “中的意外异步操作”;";Vue.js中的axios

Javascript “中的意外异步操作”;";Vue.js中的axios,javascript,vue.js,axios,Javascript,Vue.js,Axios,作为Vue.js的新手,我有一个组件需要从远程服务器获取配置文件数据: <template> <div v-if="token"> {{profile}} </div> </template> <script> import axios from 'axios'; export default { name: 'Profile', data () { return { pr

作为Vue.js的新手,我有一个组件需要从远程服务器获取配置文件数据:

<template>

 <div v-if="token">
      {{profile}}
  </div>

</template>

<script>
import axios from 'axios';

export default {
  name: 'Profile',

  data () {
    return {
          profile: {},
    }

  },

  computed: {
    token () {
      return this.$store.getters.getToken; 
    },

    mounted () {
        return axios
        .get( this.BASE_URL + '/profile')
        .then( res => {
                    this.profile = res.data;
                    console.log('profile is:', res.data);

          })            
    },

  },

}
</script>
而且

error: Unexpected side effect in "mounted" computed property  
  86 |         .get( this.BASE_URL + '/profile')
  87 |         .then( res => {
> 88 |                     this.profile = res.data;
     |                     ^
如果我从mounted中omit
return
,我也会得到以下错误:

error: Expected to return a value in "mounted" computed property

我真的很困惑。感谢您的提示以解决此问题。

装载的级别应与计算的级别相同

<script>
import axios from 'axios';

export default {
  name: 'Profile',

  data() {
    return {
      profile: {},
    };
  },
  computed: {
    token() {
      return this.$store.getters.getToken;
    },
  },
  mounted() {
    axios.get(this.BASE_URL + '/profile').then(res => {
      this.profile = res.data;
      console.log('profile is:', res.data);
    });
  },
};
</script>

从“axios”导入axios;
导出默认值{
名称:'Profile',
数据(){
返回{
档案:{},
};
},
计算:{
代币(){
返回此。$store.getters.getToken;
},
},
安装的(){
get(this.BASE_URL+'/profile')。然后(res=>{
this.profile=res.data;
log('profile is:',res.data);
});
},
};
<script>
import axios from 'axios';

export default {
  name: 'Profile',

  data() {
    return {
      profile: {},
    };
  },
  computed: {
    token() {
      return this.$store.getters.getToken;
    },
  },
  mounted() {
    axios.get(this.BASE_URL + '/profile').then(res => {
      this.profile = res.data;
      console.log('profile is:', res.data);
    });
  },
};
</script>