gpt4 book ai didi

vue.js - 通过 Vue 中的数据属性传递函数引用

转载 作者:搜寻专家 更新时间:2023-10-30 22:25:06 25 4
gpt4 key购买 nike

我正在尝试将一个函数传递给 recaptcha 以用作回调。我需要写:

data-callback="function"

在 Vue 中如何添加函数引用?我试过:

data-callback="{{ this.submitFocus }}"

data-callback="this.submitFocus"

我正在使用 Vue 2

最佳答案

Recaptcha2 使用data-callback 字符串来调用一个全局可用的函数。

根据我在 documentation 中看到的内容, 看起来没有编程方式来设置它所以你可能不得不使用这样的东西

beforeMount () {
window.submitFocus = () => { // using arrow function to preserve "this"
this.submitFocus()
}
},
beforeDestroy () {
delete window.submitFocus
}

data-callback="submitFocus"

在你的模板中。属性值只需要匹配添加到 window 的函数即可。

关于vue.js - 通过 Vue 中的数据属性传递函数引用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50034877/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com