[Vuejs]-Vue.js props and rest call

2👍

you can set config as null first, make the http request in mounted hook, and set the config value only after a response occurs. You cannot control how long the http request would take, therefore, in your component, you may think about what to display when ‘config’ is still null.

<script>
import axios from "axios";

var unit = "test";

var data = {
  unit: unit,
  config: null
};

export default {
  name: "App",
  components: {},
  data: function() {
    console.log("get data");
    return data;
  },
  mounted() {
    axios.get("/unitConfiguration/" + unit).then(response => {
      this.config = response.data;
      console.log("rest call done");
    });
  }
};
</script>

1👍

In your Sub-component you can add :

props:{

     unit:{
        type:Object,
        default:function(){
            return{}
        }
    },
    config:{
        type:Object,
        default:function(){
            return{}
        }
    },
}

Leave a comment