2

I have an issue where the Vue object is undefined in the browser, after I load in Vue with RequireJS. I'm not sure what's going on, I hope someone has some pointers to focus on.

Something worth noting is that I'm placing this code through our custom framework into a MVC C# application. Ultimately the code is placed in views and served along all other JS / HTML.

The HTML is placed first, after which the script is executed.

HTML:

<div id="aapje">
  {{ message }}
</div>

JS:

require(['https://unpkg.com/vue'], function() {
  var appje = new Vue({
    el: '#aapje',
    data: {
      message: 'Hello Vue!'
    }
  });
});

Console dump:

enter image description here

Codepen: https://codepen.io/olafjuh/pen/oKWKXG

1 Answer 1

2

To achieve expected result, pass 'Vue' as parameter to callback funtion of require

working code sample

require(['https://unpkg.com/vue'], function(Vue) {
   var appje = new Vue({
    el: '#aapje',
    data: {
      message: 'Hello Vue!'
    }
  });
});
<script src="https://cdnjs.cloudflare.com/ajax/libs/require.js/2.3.3/require.min.js"></script>
<div id="aapje">
  {{ message }}
</div>

codepen - https://codepen.io/nagasai/pen/WVjVoV

Sign up to request clarification or add additional context in comments.

2 Comments

I literally just stumbled across an example and tried that.. It's the curse of posting a question on SO and instantly finding the answer. Thanks for the response though! Hope this will save someone else time! Will mark your answer in a few minutes.
Thanks @Devilscomrade , happy coding :)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.