How do I handle click event on the button inside t

2019-06-04 02:36发布

I want to handle the button click event inside the toastr. I am using this library: https://www.npmjs.com/package/vue-toastr-2

This is my code:

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 
    }
  }
})

Basically I want that when clickMe is clicked, my function inside the component should get called. How would I do this?

This is my jsfiddle: https://jsfiddle.net/75154x8w/2/

1条回答
趁早两清
2楼-- · 2019-06-04 03:05
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');
    }
  }
})
查看更多
登录 后发表回答