[Vuejs]-How to swich current view with vue.js?

0👍

  1. Actually load vue.js somewhere.
  2. App.currentView = ‘guestmenu’.
  3. Vue is a constructor, you need to call it with new. It even yells at you if you forget: [Vue warn]: Vue is a constructor and should be called with the 'new' keyword
  4. Never mount to or . This is also a console warning!
  var GuestMenu = Vue.extend({
        template: `
              <p>Guest</p>
            `});

   var UserMenu = Vue.extend({
        template: `
                <p>User</p>
            `});
            
Vue.component('guestmenu', GuestMenu);
Vue.component('usermenu', UserMenu);

var App = new Vue({
  el: '#app',
  data:
    {
      currentView: 'guestmenu'
    }
  })

App.currentView = 'usermenu'
<script src="https://unpkg.com/vue/dist/vue.js"></script>
<div id="app">
  <component :is="currentView"> </component>
</div>

Leave a comment