我想处理烤面包机内的按钮单击事件。我正在使用此库:https://www.npmjs.com/package/vue-toastr-2

这是我的代码:

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/

最佳答案

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

关于javascript - 如何处理Toastr内部按钮上的click事件?,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/47362579/

10-12 01:23