【问题标题】:why can i not call a function of my vue component in my callback [closed]为什么我不能在我的回调中调用我的 vue 组件的函数[关闭]
【发布时间】:2021-11-14 09:00:42
【问题描述】:

我在 vue 中使用数据表和 jquery 和

> <script>
>     export default {
>       methods: {
>         ddd() {
>           alert(44444444);
>         },
>       },
>       mounted: function () {
>         let table = new DataTable("#tbl", {});
>         $("#tbl tbody").on("click", "tr", function () {
>           this.ddd();
>         });
>       },
>     };
>     </script>

为什么 ddd() 不起作用请帮助我

【问题讨论】:

标签: vue.js


【解决方案1】:

您的问题是词法范围。您提供的回调方法是一个匿名函数,它重新声明了this 的值。要解决它,请使用粗箭头。

$("#tbl tbody").on("click", "tr", () => {
  this.ddd();
});

【讨论】:

  • @AndrewMorton 完成。
猜你喜欢
  • 2021-10-15
  • 1970-01-01
  • 2018-05-20
  • 1970-01-01
  • 2020-08-12
  • 1970-01-01
  • 2020-02-21
  • 2019-06-02
  • 1970-01-01
相关资源
最近更新 更多