美文网首页
weex日常开发总结

weex日常开发总结

作者: 异乡人_4f2a | 来源:发表于2019-02-16 11:05 被阅读0次

1.取服务器返回报文中的某一个key类似num@name的值,此时用data.num@name行不通,需要改写成data["num@name"]来取值才可以

2.parseFloat()需要慎用,parseFloat()虽然是将一个值转成浮点数,一般情况下没问题,但是对于有些数字却有影响,例如将"572.57"转成浮点数,会变成572.5700000001,所以要将某一个数显示在某地方,建议用toString()

3. 安卓上屏蔽蒙板后面的点击事件

            backClick:function () {

  },

4.scroller里面嵌套list列表的时候,list不会被自动撑开,可能需要给list设置高度

5.判断是否是iPhone X等机型的判断

<div v-if="isShowReInvestList" :class="[isIPhoneX ? 'iPhoneXStyle' : 'iPhoneStyle']" @click = "backClick()">

if(weex.config.env.deviceModel == "iPhone10,3" || weex.config.env.deviceModel == "iPhone11,8" || weex.config.env.deviceModel == "iPhone11,2" || weex.config.env.deviceModel == "iPhone11,6") {

                 self.isIPhoneX = true;

 }

6.在隐藏了导航条的界面,需要返回上一级页面时,weex调用原生的方法中,写以下代码即可

[weexInstance.viewController.navigationController popViewControllerAnimated:YES]

7.三目运算嵌套的写法

<div :class="[isAndroid ? 'AndroidStyle' : isIPhoneX ? 'isIPhoneXStyle' : 'isIPhoneStyle']">

8.竖直居中

align-items: center;

水平居中

justify-content:center

9.weex调用原生方法传多个参数的用法

weex里面的写法如下:

ev.applyForBusinessLoanDialog("3",self.totalBorrowLineAmount/10000);

原生里面的写法如下:

WX_EXPORT_METHOD(@selector(applyForBusinessLoanDialog: paramets:))

-(void)applyForBusinessLoanDialog:(NSString *)type paramets:(NSString *)message {

    if([type isEqualToString:@"3"]){

        [self showAlertWithTitle:@"提示" message:[NSString stringWithFormat:@"您的累计金额已经超过%@万,暂不能申请借款。",message] defaultButtonTitle:@"确定" needMsgLabelLineSpacing:NO];

        return;

    }

}

10.weex搜索.vue文件,command + p

11.weex界面隐藏导航条

a.创建个状态栏statusBar.vue

<template>

    <div>

        <div class="iPhoneXH statusBar"  v-if="isiPhoneX"></div>

        <div class="iOSH statusBar"  v-else-if="isiOS"></div>

        <div class="androidH statusBar"  v-else-if="isAndroid"></div>

    </div>

</template>

<style scoped>

.iPhoneXH {

  height: 88px;

}

.iOSH {

  height: 40px;

}

.androidH {

  height: 0px;

}

.statusBar {

  width: 750px;

  background-color: #ffffff;

}

</style>

<script>

import { Utils } from 'weex-ui';

var device = weex.config.env;

export default {

  data() {

    return {

      isiPhoneX: weex.config.env.deviceModel == "iPhone10,3" || weex.config.env.deviceModel == "iPhone11,8" || weex.config.env.deviceModel == "iPhone11,2" || weex.config.env.deviceModel == "iPhone11,6",

      isiOS: device.platform === "iOS",

      isAndroid: device.platform === "android"

    };

  }

};

</script>

2.创建个导航栏navigationBar.vue

<template>

    <div>

        <div :class="[isAndroid ? 'isAndroidBgViewStyle' : isIPhoneX ? 'isIPhoneXBgViewStyle' : 'isIPhoneBgViewStyle']">

            <!-- 返回div -->

            <div @click="goBack()" :class="[isAndroid ? 'isAndroidBackViewStyle' : isIPhoneX ? 'isIPhoneXBackViewStyle' : 'isIPhoneBackViewStyle']">

                <image class="backImg" :src="back_img"/>

            </div>

            <!-- 标题 -->

            <text class="centerTitle">{{title}}</text>

        </div>

        <!-- 底部分隔线 -->

        <!-- <div class="bottomLine"></div> -->

    </div>

</template>

<style scoped>

    .isAndroidBgViewStyle {

        width: 750px;

        height: 100px;

        background-color: #ffffff;

        justify-content: center;

        align-items: center;

    }

    .isIPhoneXBgViewStyle {

        width: 750px;

        height: 150px;

        background-color: #ffffff;

        justify-content: center;

        align-items: center;

    }

    .isIPhoneBgViewStyle {

        width: 750px;

        height: 100px;

        background-color: #ffffff;

        justify-content: center;

        align-items: center;

    }

    .isAndroidBackViewStyle {

        padding-left: 30px;

        padding-right: 30px;

        height: 100px;

        position: absolute;

        top: 0;

        justify-content: center;

    }

    .isIPhoneXBackViewStyle {

        padding-left: 30px;

        padding-right: 30px;

        height: 150px;

        position: absolute;

        top: 0;

        justify-content: center;

    }

    .isIPhoneBackViewStyle {

        padding-left: 30px;

        padding-right: 30px;

        height: 100px;

        position: absolute;

        top: 0;

        justify-content: center;

    }

    .backImg {

        width: 18px;

        height: 40px;

    }

    .centerTitle {

        font-size: 36px;

        color: #0e1932;

    }

    .bottomLine {

        background-color: #cccccc;

        width: 750px;

        height: 1px;

    }

</style>

<script>

    var modal = weex.requireModule('modal');

    var baseUrl = require('./include/base.js').getWeexURL;

    var ev = weex.requireModule("navevent");

    export default {

        props: {

            /**

            * 导航栏标题

            */

            title: {

                type: String,

                required: true

            },

            /**

            * 是否是直接返回上一页,默认为true直接返回上一页

            */

            isBack: {

                type: String,

                default: 'true'

            }

        },

        data() {

            return {

                back_img:baseUrl+"img_back.png",

                isAndroid:false,

                isIPhoneX:false

            };

        },

        created: function () {

            if(weex.config.env.deviceModel == "iPhone10,3" || weex.config.env.deviceModel == "iPhone11,8" || weex.config.env.deviceModel == "iPhone11,2" || weex.config.env.deviceModel == "iPhone11,6") {

                  this.isIPhoneX = true;

            }

        },

        methods: {

            mounted: function () {

            var config = this.$getConfig();

            var json = JSON.parse(JSON.stringify(config));

            this.platform = json.env.platform;

            var self = this;

            if ("android" === self.platform) {

                    this.isAndroid = true;

                } else {

                    this.isAndroid = false;

                }

        },

        goBack(e) {

        if (this.isBack === 'true') {

            var self = this;

            var config = this.$getConfig();

            var json = JSON.parse(JSON.stringify(config));

                    if("android" == json.env.platform) {

                    ev.pop("", null);

                } else {

                    ev.showNavPop();

                }

            } else {

                    this.$emit("click", {e});

                }

            }

        }

    };

</script>

3.在需要隐藏导航栏的vue中使用即可导入

<template>

<div style="background-color: #f0f0f0;">

<statusBar></statusBar>

<navBar title=“导航条” isBack='false' @click="goback()"></navBar>

</div>

</template>

<script>

   /*引用自定义的状态栏控件*/

    import statusBar from './statusBar.vue';

   /*引用自定义的导航条控件*/

    import navBar from './navigationBar.vue';

    export default {

    components: {navBar,statusBar},

    }

</script>

4.记得调用隐藏原生导航条的方法: ev.hideTitle()

created: function () {

            globalEvent.removeEventListener("appear");

            globalEvent.addEventListener("appear",function(e){

                var fileName = e.page;

                if ('' !== fileName && '当前的js文件名.js' === fileName) {

                    ev.hideTitle();

                }

            });

        },

12.weex页面隐藏导航条时,界面底部出现空白的解决方案

在加载weex界面的跟控制器里面设置如下代码即可


- (void)setupFrame {

    CGFloat devH = [UIScreen mainScreen].bounds.size.height;

    BOOL isIphoneX = WJ_Device_iPhoneX || WJ_Device_iPhoneXR || WJ_Device_iPhoneXsMax;

    BOOL isHideNav = [self.pageid isEqualToString:@"apply_for_business_loan.js"] || [self.pageid isEqualToString:@"apply_for_business_loan_affirm.js"] || [self.pageid isEqualToString:@"apply_for_business_loan_complete.js"];

    CGFloatnavH = isHideNav ?0:64;

    CGFloatiPhoneXH = isIphoneX ?40:0;

    CGFloatviewH = isIphoneX ? devH : devH - iPhoneXH - navH;

    _instance.frame = CGRectMake(0, 0, CGRectGetWidth(self.view.frame), viewH);

}

相关文章

  • weex日常开发总结

    1.取服务器返回报文中的某一个key类似num@name的值,此时用data.num@name行不通,需要改写成d...

  • weex开发总结

    最近用weex开发了新浪众测app的iOS端(因开发时间紧迫,前期仅开发了iOS端,年后会继续开发Android)...

  • WEEX开发总结

    1:上拉加载更多使用的函数; 在最开始使用的是loading这个组件;在短链接的情况下就会出现;滑动就加载;无论是...

  • weex开发总结

    首先你需要必备的网站教程: 1.weex官网教程:http://weex.apache.org/cn/guide/...

  • Weex开发总结

    2018年01月21日文章、多段投放策略16年文章、安卓接入Weex18年文章、Weex发布策略19年文章、wee...

  • weex 环境搭建一 weex-toolkit

    weex开发, 安装nodejs 、weex-toolkit 、weex-pack weex官网文档:http:/...

  • (26)打鸡儿教你Vue.js

    weex框架的使用 1、weex开发入门2、weex开发环境搭建3、掌握部分weex组件模块4、了解一些vue基本...

  • [个人记录]Weex入坑

    Weex入门 官方文档 文档iOS集成 开发环境配置 安装node 安装weex开发工具 验证 weex-tool...

  • weex常见问题解析

    什么是 Weex? Weex 是使用流行的 Web 开发体验来开发高性能原生应用的框架。 Weex 致力于使开发者...

  • weex入门-Write Once, Run Everywher

    什么是 Weex ? Weex 是一个使用 Web 开发体验来开发高性能原生应用的框架。 Weex 致力于使开发者...

网友评论

      本文标题:weex日常开发总结

      本文链接:https://www.haomeiwen.com/subject/unwklqtx.html