2017-11-18 115 views
1

我想處理toastr中的按鈕點擊事件。我使用這個庫:https://www.npmjs.com/package/vue-toastr-2如何處理toastr中按鈕的點擊事件?

這是我的代碼:

var app = new Vue({ 
    el: '#app', 
    data: { 
    message: 'vue-toastr-2' 
    }, 
    created: function() { 
    this.$toastr.success('Click here to fire an event <button @click="clickMe">Hello</button>', 'Title'); 
    }, 
    methods: { 
    clickMe() { 
     alert('Clicked'); 
     // write some more code 
    } 
    } 
}) 

基本上我想要被點擊clickMe的時候,我在組件內部功能應該被調用。我將如何做到這一點?

這是我的jsfiddle:https://jsfiddle.net/75154x8w/2/

+0

我猜你undless設計的自定義組件,通常是烤麪包的消息是沒有按鍵,這是不可能實現的。在這種情況下,你需要一個模態windo – Sajeetharan

+0

這是關閉烤麪包的按鈕? ..如果是的話,這是支持開箱。如果沒有,我不認爲這將是可能的使用這個組件,除非整個烤麪包可點擊而不是隻是按鈕 –

回答

1
var app = new Vue({ 
    el: '#app', 
    data: { 
    message: 'vue-toastr-2' 
    }, 
    created: function() { 
    this.$toastr.success('Click here to fire an event <button onclick="app.clickMe()">Hello</button>', 'Title'); 
    }, 
    methods: { 
    clickMe() { 
     alert('Clicked'); 
    } 
    } 
}) 
+0

'onclick =「app.clickMe()」' ,與括號一起使用。 –

+0

@RichardMatsen Thanx,編輯。 – WaldemarIce

+0

乾杯,很好找。 –