我在laravel刀片模板中包含es6 javascript类时遇到问题。我收到错误Uncaught ReferenceError:未定义OptionsCalculations
我的主类OptionsCalculations位于文件“ OptionsCalculations.js”中,如下所示:
'use strict';
export class OptionsCalculations {
constructor(premium, strikePrice, expiry){
this.setPremium(premium);
this.setStrikePrice(strikePrice);
this.setExpiry(expiry);
}
get premium(){
this._premium;
}
set premium(premium){
this._premium = premium;
}
get strikePrice(){
this._strikePrice;
}
set strikePrice(strikePrice){
this._strikePrice = strikePrice;
}
get expiry(){
this._expiry;
}
set expiry(expiry){
this._expiry = expiry;
}
get closeOutPremium(){
this._closeOutPremium;
}
set closeOutPremium(closeOutPremium){
this._closeOutPremium = closeOutPremium;
}
get breakEven(){
this._breakEven;
}
set breakEven(breakEven){
this._breakEven = breakEven;
}
}
CallOptionsCalculations类扩展了OptionsCalculations,它位于文件“ CallOptionsCalculations.js”中,位于l中
'use strict';
export class CallOptionsCalculations extends OptionsCalculations {
constructor(premium, strikePrice, expiry){
super(premium, strikePrice, expiry);
}
}
我的javascript文件在webpack.mix.js中定义
.js('resources / js / class / OptionsCalculations.js','public / js / class') .js('resources / js / class / CallOptionsCalculations.js','public / js / class')
在我的app.js中
require ('./class/CallOptionsCalculations');
require ('./class/OptionsCalculations');
import {OptionsCalculations} from './class/OptionsCalculations';
import {CallOptionsCalculations} from './class/CallOptionsCalculations';
在我的刀片服务器模板中,我有以下javascript:
$(document).ready(function(){
var callRollForm = document.getElementById('call-roll-form');
var putRollForm = document.getElementById('put-roll-form');
callRollForm.addEventListener('blur', function( event ) {
let callOptionsCalculations = new CallOptionsCalculations(
callRollForm.newCallPremium.value,
callRollForm.newCallStrikePrice.value,
callRollForm.newCallExpiration.value
);
}, true);
putRollForm.addEventListener('blur', function( event ) {
console.log('put roll form');
}, true);
});
在onblur事件上,这是实例化该类并收到错误的时间。