mercredi 27 décembre 2017

Imported Javascript function not defined when called from html

I'm learning laravel 5.5 and VueJs, my issue is when I export some functions from a js file and import it from a second js file it cannot be called from html body. Example:

A.js

function funA(){
}
export {funA};

B.js

import {funA} from './A.js';

At this point if I use the function funA inside the B.js it works, however if I use it on a html page it says funA is not defined. For example:

<!DOCTYPE html>
<html lang="en">
<body>
  <button onClick="funA()"></button>
  <script src=""></script>
</body>
</html>

My webpack configuration is something like this:

mix.scripts('resources/assets/js/libs/materialize.js', 'public/js/libs/materialize.js')
    .js('resources/assets/js/A.js', 'public/js/js/A.js')
    .js('resources/assets/js/B.js', 'public/js/B.js');

Any help would be appreciated. Thank you in advanced.



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire