嗨,我在laravel項目中的人我有一些javascript助手功能,利用jquery
我想提取到一個單獨的地方,應用程序的所有部分都可以使用。這些都是存儲在helper.js
功能:如何在laravel應用程序中添加自定義的JavaScript
// bootbox function to delete records
// it utitlizes the bootbox library
window.bootbox_delete = function (message, route, row) {
// body...
bootbox.dialog({
message: message,
title: "<i class='glyphicon glyphicon-trash'></i> Delete !",
buttons: {
success: {
label: "No",
className: "btn-success",
callback: function callback() {
$('.bootbox').modal('hide');
}
},
danger: {
label: "Delete!",
className: "btn-danger",
callback: function callback() {
$.ajax({
type: 'DELETE',
url: route
}).done(function (data) {
bootbox.alert('<b>' + data.name + '</b> successfully deleted');
//removing the row that have been deleted
jQuery(row).fadeOut('slow');
}).fail(function() {
bootbox.alert('Something Went Wrong .... Please contact administrator');
});
}
}
}
});
}
// function that displays notification
window.notify = function(message) {
// body...
$.notify({
icon: 'fa fa-check',
message: message
}, {
type: 'success',
timer: 4000,
offset: 20,
spacing: 10,
z_index: 1031,
delay: 5000,
placement: {
from: "top",
align: "right"
},
animate: {
enter: 'animated fadeInDown',
exit: 'animated fadeOutUp'
}
});
}
我所做的是我添加helper.js
到resources/assets/js
並編譯成public/js/app.js
與npm run dev
但每當我想看看,如果一切正常,我得到這些錯誤:
通知沒有被定義
bootbox_delete沒有定義
你可以顯示你的'app.js'文件中包含'helper.js'嗎?即你需要''app.js'文件中的'helper.js'文件還是要在'wekpack.mix.js'文件中編譯它?要麼你可以爲此顯示代碼。 –