使用远程app.weex.js发生错误,

发布于 2022-09-04 20:40:07 字数 1242 浏览 13 评论 0

weex编译成安卓项目, 并且把app.weex.js部署在远程服务器,
但是加载页面的时候却生如下错误:

项目地址: weex_android_demo
app.weex.js地址: http://zhiliao.weex.zhaokuo.c...
web端可以正常运行,可是在安卓端却发下面两个错误:

  1. 点击接收通知菜单时发生 render error错误, 错误截图如下:
    rendererror

  2. 点击其他三个菜单时, 发生network error错误, 错误截图如下:
    networkError

页面架构: 单页
路由方案: Vue-Router
api请求: Axios

这是为什么?大家可以解答一下么??

我目前的思路是:
第一个错误是不是weex规定某些语法不能使用, 但是我用了?
这里是第一个页面的源码: https://github.com/zhaokuohah...

第二个错误, 她说确认run server , 但是我已经将代码部署打远程了, 而且已经确认这加载的就是远程的代码, 所以应该不是renserver的问题, 我猜测会不会是axios的问题??

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

偏爱你一生 2022-09-11 20:40:07

第一个渲染错误,可能是<router-link>标签的问题,因为weex这边官网给的示例是不建议使用<router-link>标签,而是直接使用router.push的形式。(不过,你的js页面,我使用weexplayground app ios版,是跳转正常的,所以不确定安卓是什么情况)
http://weex-project.io/cn/ref...

第二个的话,建议用weex提供的module:stream试试,他封装了原生的网络请求。
http://weex-project.io/cn/ref...

水晶透心 2022-09-11 20:40:07

路由跳转建议直接使用router.push的形式
我这边使用的是服务器端封装好的一个路由跳转模块

   methods: {
            jump: function (item) {
                weex.requireModule('lc_event').jumpToPage('wxlc://' + server + item.url);
            }

        },

数据请求 在weex中 建议使用它内部的stream模块

     weex.requireModule('stream').fetch({
                   method:'GET',
                   type:'json',
                   url:'/assest/data.json'
               },function (response) {
                       self.movieList.push.apply(self.movieList, response.data.subjects);
               })
情丝乱 2022-09-11 20:40:07

谢谢两位的答案, 恰恰是这两个问题, 现在两个问题都搞定了, 我把两部分的代码分别贴出来给大家做个参考吧:

关于vue-router:

错误代码(router-link导航链接):

<div class="footer">
        <div class="footer-item">
          <router-link to='/'>
            <text class="text-center">接收通知</text>
          </router-link>
        </div>
        <div class="footer-item">
          <router-link to='/sendtask'>
            <text class="text-center">发送通知</text>
          </router-link>
        </div>
        <div class="footer-item">
          <router-link to="/joingroup">
            <text class="text-center">加入群</text>
          </router-link>
        </div>
        <div class="footer-item">
          <router-link to="/login">
            <text class="text-center">登录</text>
          </router-link>
        </div>
    </div>

正确代码(编程式导航)

<div class="footer">
        <div class="footer-item" @click="jump('')">
            <text class="text-center">接收通知</text>
        </div>
        <div class="footer-item" @click="jump('sendtask')">
            <text class="text-center">发送通知</text>
        </div>
        <div class="footer-item" @click="jump('joingroup')">
            <text class="text-center">加入群</text>
        </div>
        <div class="footer-item" @click="jump('login')">
            <text class="text-center">登录</text>
        </div>
    </div>

关于请求:

错误代码(axios):

login(){
                let tvm = this;
                axios.post('http://zhiliao.server.zhaokuo.cc/api/Account/login',tvm.account).then(function(res){
                    console.log(res);
                });
            }

正确代码(stream):

var stream = weex.requireModule('stream')

login(){
                let tvm = this;
                
                stream.fetch({
                    method:'POST',
                    headers :{
                        'Content-Type':'application/json' //如果需要json传输,content-type要更改
                    },
                    type:'json',
                    body:JSON.stringify(tvm.account), //请求体, 直接收string参数, 所以要转化一下
                    url:'http://zhiliao.server.zhaokuo.cc/api/Account/login'
                },function(res){
                    console.log(res);
                });
            }
呢古 2022-09-11 20:40:07

请问下远程配置在Android那里面进行修改

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文