2017-07-21 35 views
2

我是VueJS的新手。我想在模糊上發出自定義事件。我成功地做了它,但發現難以捕獲通過在我的根Vue實例中發出的參數。我如何去做呢?

<div id = "root"> 
    <coupon @applied = "checkApplied()"></coupon> 
    <p v-if = "showText">Coupon code successfully applied</p> 
</div> 

Vue.component('coupon',{ 
    template : ` 
     <input type = "text" placeholder = "Enter the coupon" @blur="checkApplied($event.target.value)"> 
     `, 

    methods : { 
     checkApplied(value){ 
      console.log(value); 
      this.$emit('applied',[value]); 
     } 
    } 
}); 
var app = new Vue({ 
    el : '#root', 
    data : { 
     showText : false, 

    }, 

    methods : { 
     checkApplied(value){ 
      console.log(value); 
      this.showText = true; 
     } 
    }, 

    } 

}) 

正如你可以看到當被髮射的應用情況下,我把它傳遞給工作,現在我該怎樣傳遞參數,我從@applied拿到並將它傳遞給checkApplied()。我曾嘗試這一點,但它沒有鍛鍊@applied = checkApplied(value)

回答

0

相反的@applied=checkApplied(value)你需要做的@applied=checkApplied($event)

相關問題