[Vuejs]-Can props be accessed in beforecreated of vue?

0👍

Please check the following snippet, looks like your code is fine:

const app = Vue.createApp({
  data() {
    return {
      msg: 'aaa',
    };
  },
})
app.component('Child', {
  template: `<div>{{ message }}</div>`,
  props: ['message'],
  beforeCreate() {
    console.log('before create: ', this.message)
  }
})
app.mount('#demo')
<script src="https://unpkg.com/vue@3.2.29/dist/vue.global.prod.js"></script>
<div id="demo">
  <child :message="msg"></child>
</div>

Leave a comment