【问题标题】:How to pass axios response object from a parent component to child component using props in vue如何使用vue中的props将axios响应对象从父组件传递给子组件
【发布时间】:2019-07-03 23:18:40
【问题描述】:

我有一个名为prospect.vue 的父组件和一个名为task.vue 的子组件。我想使用道具将repsonse数据对象发送到子组件task.vue我该怎么做。

PROSPECT.VUE

    <div class="card-body dashboardContainer">
            <mandate/>
    </div>


export default {
  name: 'prospects',
  components: {
    mandate 
  },
  data() {
       return {
        sendata:{}
      } 
    },
    methods: {
                fetchData(){
                  axios.get('http://localhost:3000/data') .then((response) => {
                  //console.log(response.data);
                  this.sendata=response.data;
                  console.log(this.sendata);

                 })
               .catch(function (error) {
                console.log(error);
                 });
              }
    },
    created(){
    // Fetch Data
    this.fetchData();
}
}

【问题讨论】:

标签: vue.js axios


【解决方案1】:

你来了

PROSPECT.VUE

    <div class="card-body dashboardContainer">
            <mandate :data="this.sendata"/>
    </div>


export default {
  name: 'prospects',
  components: {
    mandate 
  },
  data() {
       return {
        sendata:{}
      } 
    },
    methods: {
                fetchData(){
                  axios.get('http://localhost:3000/data') .then((response) => {
                  //console.log(response.data);
                  this.sendata=response.data;
                  console.log(this.sendata);

                 })
               .catch(function (error) {
                console.log(error);
                 });
              }
    },
    created(){
    // Fetch Data
    this.fetchData();
}
}

【讨论】:

    猜你喜欢
    • 2020-03-30
    • 2020-07-26
    • 1970-01-01
    • 2018-05-25
    • 1970-01-01
    • 1970-01-01
    • 2018-12-28
    • 2021-07-19
    • 2016-05-10
    相关资源
    最近更新 更多