繁体   English   中英

如何在vue中使用props将axios响应对象从父组件传递到子组件

[英]How to pass axios response object from a parent component to child component using props in vue

我有一个名为prospect.vue 的父组件和一个子组件mission.vue。 我想使用 props 将响应数据对象发送到子组件授权.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();
}
}

你去吧

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();
}
}

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM