[英]Import external js with Vue
假设我在resources/assets/js
有2个js文件,一个是app.js
,另一个是ext_app.js
ext_app.js
有一个函数,如下所示:
function testFunction() {
// function code
}
在app.js
:
require('./bootstrap');
require('./ext_app.js');
const app = new Vue({
// other stuff
mounted: function() {
// Call my test function from ext_app.js
testFunction();
}
});
跑npm run dev
并查看public/js/app.js
, ext_app.js
代码在那里,无论如何都很好。 但是,该应用在Chrome上运行时返回以下错误:
[Vue warn]: Error in mounted hook: "ReferenceError: testFunction is not defined"
我想念什么?
您需要先导出testFunction,然后才能使用它。
module.exports = function testFunction() {
// function code
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.