我正在VueJS 1.0中练习,而且我正在学习组件.在这里example,有一个input元素,必须从API 提供coupon或某种类型的code.我必须验证.我有我的<coupon >组件,并有道具when-applied.在when-applied必须调用父功能setCoupon,但它不会.
我只有这个错误this.whenApplied is not a function.
<div id="demo" class="list-group">
<script id="coupon-template" type="x-template">
<input type="text" v-model="coupon" v-on:blur="whenCouponHasBeenEntered">
<div v-text="text"></div>
</script>
<coupon when-applied="setCoupon"></coupon>
</div>
Run Code Online (Sandbox Code Playgroud)
这是我的app.js档案
Vue.component('coupon', {
template: '#coupon-template',
props: ['whenApplied'],
data: function() {
return {
coupon: '',
invalid: false,
text: ''
}
},
methods: {
whenCouponHasBeenEntered: function() {
this.validate();
},
validate: function() {
if( this.coupon == 'FOOBAR') { …Run Code Online (Sandbox Code Playgroud)