Home  >  Q&A  >  body text

javascript - How to call native app methods (Android, ios) in vuejs?

I defined a method to call the app method

$.execNativeCommand = function (command, data, options) {
    options = options || {};
    $.extend(true, options, defaultCommandOptions);
    return new Promise(function (r, j) {
        try {
            window.NativeBridge(command, data);        //NativeBridge是app 端注入的一个方法
            r();
        } catch (err) {
            if (options.showError) {
                $.alert("调用原生APP接口失败,错误消息:" + (err.message || "未知错误"));
            }
            if (options.gotoDownload) {
                var url = (options.getDownloadUrl || $.noop)(command, data);
                if (url) {
                    location.href = url;
                }
            }
            j();
        }
    });
}
调用方法:
 $.execNativeCommand('jumpGroupChat', cacheDetail.activityGroupId);

But how to use the native methods on the app side in vue?

漂亮男人漂亮男人2713 days ago921

reply all(1)I'll reply

  • 世界只因有你

    世界只因有你2017-05-16 13:25:44

    Same way of writing. Is there no window object in vue?

    reply
    0
  • Cancelreply