Error while mounting a component on a div instead of a body

Viewed 935

I am trying to mount a component on a div element using document.querySelector('.widget') but it throws an error

main.js looks like

const app = new App({
    target: document.querySelector('.widget'),
});

index.html looks like

    <body>
    <script src='bundle.js'></script>
    <div class="widget" id="widget"></div>
    </body>

I get an error Uncaught Error: 'target' is a required option

1 Answers

You load the bundle.js script before the div tag in the document. If you put the script tag after the div it will work as expected.

<body>
  <div class="widget" id="widget"></div>
  <script src='bundle.js'></script>
</body>
Related