我想從其他JS文件中調用我的通知函數,但它總是返回undefined
。來自其他js文件的Javascript(Vue)調用函數返回undefined
notification.js
function notification(message, level = 'success') {
Lobibox.notify(level, {
delayIndicator: false,
msg: message
});
}
addToCart.vue
<template>
<div>
<button class="button dark small" @click="addToCart(menu, price)">
<i class="fa fa-cutlery fa-lg m-right-5"></i>
Pilih Menu
</button>
</div>
</template>
<script>
export default{
props: ['menu', 'price'],
methods:{
addToCart(menu, price){
const currentPoint = $('#current_point').val();
if(price > currentPoint){
return notification('Point is not enough', 'error')
}
}
}
}
</script>
app.js
Vue.component('addtocart', require('./components/AddToCart.vue'));
new Vue({
el: '#app'
});
HTML:
<script src="{{ asset('js/notification.js') }}"></script>
<script src="{{ asset('js/app.js') }}"></script>
每次price > currentPoint
得到稱它總是返回我Uncaught ReferenceError: notification is not defined
。
我使用LaravelMix進行編譯。
任何解決方案?
您的通知方法沒有任何return語句。所以它返回undefined –