weex踩坑记录

weex框架样式问题--我暂时使用最基本的样式css,weex前端开发的话web端会显示各种的html标签。写出的样式也都会显示的很好,但是在app端的话,就没有很好的兼容性,只是支持文档中的一些标签,样式也是只支持sing-class。

weex的请求框架steam,是weex的自带model,在处理post的时间要对传入的数据进行处理,不然不会出现你想要的数据。处理方式:

let http,jsonType = ''
if (WXEnvironment.platform === 'Web') {
     http = http://yapi.youximao.cn/mock/141
    jsonType = 'json'
} else {
    http =  'http://102.108.50.100:8880/'
    jsonType = 'json'
}
let stream = weex.requireModule('stream')
const methods = {
        toParams(obj) {
            var param = ""
            for(const name in obj) {
                if(typeof obj[name] != 'function') {
                    param += "&" + name + "=" + encodeURI(obj[name])
                }
            }
            return param.substring(1)
        },
        GET (api, callback) {
            return stream.fetch({
                method: 'GET',
                type: 'json',
                url: http + api
            }, callback)
        },
        POST (api, data, callback) {
            return stream.fetch({
                method: 'POST',
                headers:{'Content-Type': 'application/x-www-form-urlencoded'},
                type: jsonType,
                body: this.toParams(data),
                url: http + api
            }, callback)
        }
}
export default methods

碰到了一个很坑的问题,network获取正常数据但是在打印在控制台的时间data为null。这个问题应该是后端返回数据有问题,我修改了下mock的数据皆可以了。

weex刚刚进入页面的话要执行的函数,要写在钩子函数

beforeMount

里面这样才会执行,写在created里面 在app端是不执行的。

    created () {
        window.initFontSize(750)
    },
    beforeMount () {
        this.getAllInitData()
    },

 weex发出请求在web端会出现跨域问题。mock的话是不会的,我放到了开发环境就出现了跨域问题,后端大牛是设置的可以跨域的。第一,修改hosts文件。可以自行百度,很多牛人帮忙解答,再者就是浏览器的安全机制保护,我是chorme调试的,把chorme浏览器设置成可以跨域的浏览器。

出现上面的命令就可以进行在web端调试。

碰到问题大家可以一起讨论,大家一起踩坑。。472027267

猜你喜欢

转载自www.cnblogs.com/sanye00liubingjian/p/10024675.html