研究了一周weex,对遇到的坑和bug做一个总结,能解决的出个解决方案,让后来的路人少掉坑吧
在<text>元素中,如果设置了字体为iconfont,文本通过{ {}}方式绑定的话,x
字符会显示为一个类似打印机图标
参考在的回答
在template中 text写死 时,weex-template-compiler在编译阶段使用了he进行decode,而在template中Mustache进行数据绑定fontName(fontName:"")时不会进行decode.
解决方案:
方案一
var he = require('he'); getFontName: function() { return he.decode(this.fontName) }
方案点评:
- 引入了
he
导致打包体积过大 - 需要手动处理非常麻烦
- 带官方解决
方案二:
通过正则表达式将iconfont的字符取出替换,用String.fromCharCode()方法处理
decode(text) { // 正则匹配 图标和文字混排 eg: 我去上学校,天天不迟到 let regExp = /&#x[a-z]\d{3,4};?/; if (regExp.test(text)) { return text.replace(new RegExp(regExp, 'g'), function (iconText) { let replace = iconText.replace(/&#x/, '0x').replace(/;$/, ''); return String.fromCharCode(replace); }); } else { return text; } }
<refresh>的onpullingdown
方法在iOS下拉后会一直调用
同问
解决方案:
无