[Vuejs]-Vue prop default value not working properly

4πŸ‘

βœ…

In this case you will inherit the default value:

<pair></pair>

In this case you will always inherit the value of selectedExchange, even if it’s null or undefined:

<pair :selectedExchange="this.selectedExchange"></pair>

So, in your case, you have to handle the default value on parent component.

This should work:

export default {
  name: 'App',
  components: { exchange, pair, trades },
  data(){
    return{
      selectedExchange: 'acx' // default value
    }
   },
   methods: {
     updateExchange(updatedExchange){
       this.selectedExchange = updatedExchange
     }
   },
  };
πŸ‘€Fab

Leave a comment