I have a project and in project i have 3 file :
1 . index.html
2 . main.js
3 . Vue.js (Vue library)
My index.html:
<!DOCTYPE html>
<html>
<head>
<title></title>
<style type="text/css">
body{
padding-top: 40px;
}
</style>
</head>
<body>
<div id="root" class="container">
<coupon @applied="OnCouponApplied"></coupon>
<h1 v-show="couponApplied">applied</h1>
</div>
<script src="../index/vue.js"></script>
<script src="main.js"></script>
</body>
</html>
And my main.js :
window.Event=new Vue();
Vue.component('coupon',{
name:'coupon',
template:'<input placeholder="enter you`r code" @blur="OnCouponApplied">',
methods:{
OnCouponApplied(){
Event.$emit('applied');
}
}
});
new Vue({
el:'#root',
data:{
couponApplied:false
},
created(){
Event.$on('applied',()=>alert('handle!'));
}
});
But I have two warnings:
Warnings :
vue.js:597 [Vue warn]: Property or method "OnCouponApplied" is not defined on the instance but referenced during render. Make sure that this property is reactive, either in the data option, or for class-based components, by initializing the property. See: https://vuejs.org/v2/guide/reactivity.html#Declaring-Reactive-Properties.
(found in <Root>)
vue.js:597 [Vue warn]: Invalid handler for event "applied": got undefined
found in
---> <Coupon>
<Root>
It work correctly and now I want too know is there any solution to these warnings?
<coupon @applied="OnCouponApplied"></coupon>
is usingOnCouponApplied
which doesn't exist in the root Vue instance – Emile Bergeron