Using Vue JS with JS requirement?

I installed the following through Bower:

  • jQuery 3.1.0
  • Vue 1.0.26
  • Require.js 2.2.0

But when I load my site, "Vue" is undefined.

I tried var vue = require('Vue')and stuff, but it doesn't work.

Vue says this is an AMD module, as well as Require.js ... What am I missing?

+3
source share
1 answer

var vue = require('Vue')will not work on its own. Or you:

  • Change it to the form requirethat performs the callback:

    require(['Vue'], function (vue) {
      // code that uses Vue
    });
    
  • Or put the call requireinto the call define:

    define(function (require) {
      var vue = require('Vue');
    });
    

Linus Borg , require - CommonJS, RequireJS , , define. (. this.)

+6

Source: https://habr.com/ru/post/1651784/


All Articles