首页 > 解决方案 > Axios 获取单一配置文件

问题描述

Q) 使用 Axios 和 Vue 传递 id 并获取“Get”请求的正确方法是什么。

我有 Vue 组件,它具有数据对象和 pId -key 的值。

我已经检查过 pId 是否有价值。

个人资料 ID:{{ pId }}

给出值 1。

data() {
    return {          
      pId: ''
    }
  },
methods: { 
    loadProfile(){
        this.status = 'Loading ....';
        axios.get("/profile/${pId} ")

        .then(function(response){
           this.profile = response.data.profile;
        })
        .catch(e => {
        this.errors.push(e)
        })
      },
init(){
        console.log('Profile mounted');
        EventBus.$on('creds' , key =>{
             [this.pId, this.uId] = key;
        })
}
  mounted(){
    this.init()
  },
  created: function() {

    this.loadProfile();
  }

谢谢米卡。

标签: vuejs2axioslaravel-7.x

解决方案


您必须使用``作为模板字符串。

所以正确的方法是:axios.get(`/profile/${this.pId}`)


推荐阅读