黑娃儿866 2023-05-01 17:48 采纳率: 0%
浏览 47
已结题

weex a组件、navigator跳转问题

weex件了一个页面,通过ios/Android/web进行访问js测试,a组件及按钮navigator跳转在Android无效,使用Utils.goToH5Page在Android也无效

<script>
goToH5Page (jumpUrl, animated = false, callback = null) {
    const Navigator = weex.requireModule('navigator');
    const jumpUrlObj = new Utils.UrlParser(jumpUrl, true);
    const url = Utils.appendProtocol(jumpUrlObj.toString());
    Navigator.push(
      {
        url: Utils.encodeURLParams(url),
        animated: animated.toString()
      },
      callback
    );
  },

</script>

<template>
  <div>
    <wxc-button text="Open Popup"
                @wxcButtonClicked="buttonClicked">
    </wxc-button>
    <wxc-popup width="500"
               pos="left"
               :show="isShow"
               @wxcPopupOverlayClicked="overlayClicked">
    </wxc-popup>
    <a href="http://www.taobao.com">
    <text>Jump2323</text>
  </a>
  </div>
</template>
<script>
  const navigator = weex.requireModule("navigator");
  import { WxcButton, WxcPopup,Utils } from 'weex-ui';
  import downgrade from '@weex-project/downgrade';
  //downgrade.force()
  module.exports = {
    components: { WxcButton, WxcPopup,Utils },
    data: () => ({
      isShow: false
    }),
    methods: {
      buttonClicked () {
        
          this.isShow = true;
          console.log(Utils.encodeURLParams("http://www.baidu.com"));
          
          navigator.push({
          url: "http://www.taobao.com",
          animated: "true"
        });
        this.src = 'http://m.taobao.com'
      },
      overlayClicked () {
        this.isShow = false;
      },getEntryUrl(name) {
      // 判断当前的环境,适配web端
          if (weex.config.env.platform === "Web") {
              return './' + name + '.html'
          } else {
              let arr = weex.config.bundleUrl.split('/');
              arr.pop();
              arr.push(name + '.js');
              return arr.join('/');
          }
      }
    }
  };
</script>

img

img

  • 写回答

3条回答 默认 最新

  • Jackyin0720 2023-05-01 20:42
    关注

    以下思路仅供参考:

    可能是以下几个原因导致在Android端使用Utils.goToH5Page时无效:
    1、在Android端,需要在应用的Manifest文件中添加对WebView组件的权限声明,例如:
    {  
      "permission": {  
        "android.permission.READ_EXTERNAL_STORAGE": {  
          "scope.userVisible": true,  
          "description": "允许用户访问外部存储"  
        }  
      },  
      "application": {  
        "webview.enabled": true  
      }  
    }
    
    2、需要将WebView组件添加到MainActivity中,例如:
    public class MainActivity extends AppCompatActivity {  
        private WebView webView;  
      
        @Override  
        protected void onCreate(Bundle savedInstanceState) {  
            super.onCreate(savedInstanceState);  
            setContentView(R.layout.activity_main);  
      
            webView = findViewById(R.id.web_view);  
            webView.getSettings().setJavaScriptEnabled(true);  
            webView.getSettings().setDomStorageEnabled(true);  
            webView.getSettings().setDatabaseEnabled(true);  
            webView.getSettings().setAllowFileAccess(true);  
            webView.getSettings().setAppCacheEnabled(true);  
            webView.getSettings().setAllowUniversalAccessFromFileURLs(true);  
            webView.getSettings().setCacheMode(WebSettings.LOAD_CACHE_ELSE_NETWORK);  
            webView.getSettings().setJavaScriptCanOpenWindowsAutomatically(true);  
            webView.getSettings().setUseWideViewPort(true);  
        }  
      
        public void gotoH5Page() {  
            if (null == webView) return;  
      
            webView.loadUrl("https://example.com");  
            webView.setWebViewClient(new WebViewClient() {  
                @Override  
                public void onPageFinished(WebView view, String url) {  
                    super.在Android端,需要在应用的AndroidManifest.xml文件中添加对WebView组件的权限声明,例如:  
      
      
    ```xml  
    <uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />  
      
    <application  
        android:allowBackup="true"  
        android:icon="@mipmap/ic_launcher"  
        android:label="@string/app_name"  
        android:theme="@style/AppTheme" >  
        <activity  
            android:name=".MainActivity"  
            android:label="@string/app_name" >  
            <intent-filter>  
                <action android:name="android.intent.action.MAIN" />  
                <category android:name="android.intent.category.LAUNCHER" />  
            </intent-filter>  
        </activity>  
    </application>
    3、可能需要调整一下AndroidManifest.xml中WebView组件的权限,例如:
    <uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />  
      
    <application  
        android:allowBackup="true"  
        android:icon="@mipmap/ic_launcher"  
        android:label="@string/app_name"  
        android:theme="@style/AppTheme" >  
        <activity  
            android:name=".MainActivity"  
            android:label="@string/app_name"  
            android:hardwareAccelerated="true"  
            android:configChanges="orientation|screenSize
    
    
    评论

报告相同问题?

问题事件

  • 系统已结题 5月9日
  • 修改了问题 5月1日
  • 创建了问题 5月1日