Skip to content
Advertisement

Is there way to hook vue component ready (initialize)

see my demo, I hope hook component ready with following code:

<body>
<div id="app">
  <ro-tag></ro-tag>
</div>
<script>
  Vue.component("ro-tag", {
    ready: function () {
      console.log("ready")
    },
    template: "<div></div>"
  })
  new Vue({el: "#app"})
</script>
</body>

the ready function isn’t invoked.

Advertisement

Answer

ready has been replaced with mounted hook in vue 2.x.x. you can use mounted hook which gets:

Called after the instance has just been mounted where el is replaced by the newly created vm.$el

see updated fiddle.

User contributions licensed under: CC BY-SA
9 People found this is helpful
Advertisement