問題vue
vue.js實現git
<template> //頁面根節點 <div @onAndroidBack="onAndroidBack" @ready="ready" @actived="actived" @deactived="deactived" class="container"> </div> </template> <script> methods: { //頁面ready 頁面傳參 ready(param){ let p = JSON.stringify(e.param) console.log('pageA頁面傳參數=' + p); }, //頁面激活 param 頁面傳參 actived(param){ }, //頁面失活 deactived(){ }, // onAndroidBack(){ uNavigator.pop(); }, onClick(){ uNavigator.popTo({index:-1,tagCode:"pageb",param:{test:'testB'}},() => {} ); } }, </script>
Android實現:github
public void onBackPressed() { WXComponent comp = mInstance.getRootComponent(); if (comp != null) { WXEvent events = comp.getDomObject().getEvents(); boolean hasBack = events.contains(UConstants.Event.ONANDROIDBACK); if (hasBack) { WXBridgeManager.getInstance().fireEvent(mInstance.getInstanceId(), comp.getRef(), UConstants.Event.ONANDROIDBACK, null, null); return; }else { super.onBackPressed(); } } super.onBackPressed(); }
@Override protected void onNewIntent(Intent intent) { super.onNewIntent(intent); setIntent(intent); if (intent == null) { return; } if (intent.getStringExtra("params") != null) { String params = intent.getStringExtra("params"); String backTag = intent.getStringExtra("backTag"); if (!TextUtils.isEmpty(params)) { WXComponent comp = mInstance.getRootComponent(); if (comp != null) { WXEvent events = comp.getDomObject().getEvents(); boolean hasActive = events.contains(UConstants.Event.ACTIVED); if (hasActive) { Map<String, Object> data = new HashMap<>(); data.put("param",params); data.put("tagCode", backTag); WXBridgeManager.getInstance().fireEvent(mInstance.getInstanceId(), comp.getRef(), UConstants.Event.ACTIVED, data, null); // } } } } } }
@Override public void onViewCreated(WXSDKInstance wxsdkInstance, View view) { super.onViewCreated(wxsdkInstance, view); WXComponent comp = mInstance.getRootComponent(); if (comp != null) { WXEvent events = comp.getDomObject().getEvents(); boolean hasReady = events.contains(UConstants.Event.READY); if (hasReady) { Map<String, Object> data = new HashMap<>(); data.put("param", wxInfo.getParam()); WXBridgeManager.getInstance().fireEvent(mInstance.getInstanceId(), comp.getRef(), UConstants.Event.READY, data, null); } } if (!isHasNavBar) { setTranslateAnimation(getContainer()); } }
@Override public void onPause() { super.onPause(); WXComponent comp = mInstance.getRootComponent(); if (comp != null) { WXEvent events = comp.getDomObject().getEvents(); boolean hasDeactived = events.contains(UConstants.Event.DEACTIVED); if (hasDeactived) { WXBridgeManager.getInstance().fireEvent(mInstance.getInstanceId(), comp.getRef(), UConstants.Event.DEACTIVED, null, null); } } if (mIsShakeDetectorStarted && mShakeDetector != null) { mShakeDetector.stop(); mIsShakeDetectorStarted = false; } } @Override public void onResume() { super.onResume(); if (!mIsShakeDetectorStarted && mShakeDetector != null) { mShakeDetector.start((SensorManager) getApplicationContext().getSystemService(Context.SENSOR_SERVICE)); mIsShakeDetectorStarted = true; } }