How to use laravel mix define global javascript function

為{幸葍}努か 提交于 2019-12-06 13:45:07

If you need to use it outside of your bundled JavaScript files you can attach it to the window object

window.test = function () {
  console.log('test');
}

Which you can then use in other files, such as your blade template files as

window.test();

Or if you want to use it within your bundled JavaScript files you can import it as a module

// test.js
export default function test() {
    console.log('test');
}

// other.js
import test from 'test.js';

test();

As long as you are compiling your files with Laravel Mix as described here in the docs.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!