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