[Vuejs]-Why vue cli 3 template or any other template has `h => h(App)` on main.js instead of just `new Vue(App)`?

1πŸ‘

βœ…

Yes, there is a benefit – when you use the options object you can also add Vue-Router, Vuex, define some data, computed properties, watchers, methods and even some lifecycle hooks. For example:

new Vue({
  data:
  {
    currentUser: null,
    lastError: null,
    showLoadingSpinner: false,
  },
  computed:
  {
    baseURL()
    {
      return process.env.BASE_URL;
    }
  },
  created()
  {
    this.$on('logout', this.logout);
  },
  beforeDestroy()
  {
    this.$off('logout', this.logout);
  },
  router: myRouter,
  store: myStore,
  render: h => h(App),
}).$mount('#app');

Leave a comment