Vue和安卓方法互调

一、Vue调用安卓封装好的方法

直接用window.android.方法名

window.android.takePhoto(params);

二、安卓调用Vue的方法

Vue的方法要挂载到window上

mounted() {
    //将要给原生调用的方法挂载到 window 上面
    window.callJsFunction = this.callJsFunction
},
data() {
    return {
        msg: "哈哈"
    }
},
methods: {
    callJsFunction(str) {
        this.msg = "我通过原生方法改变了文字" + str
        return "js调用成功"
    }
}

安卓代码里写

@Override
public void callVueJS() {
    tbsWebView.post(new Runnable() {
        @Override
        public void run() {
            webView.loadUrl("javascript:callJsFunction('soloname')");
        }
    });
}
原文地址:https://www.cnblogs.com/zhaobao1830/p/14345423.html