新年伊始,回顾过去的一年,收获不少,以前一直在研究weex,说内心话感受心好累,官方文档不全,社区不活跃,遇到不少坑,官方发布的版本有时都有坑,搞得我都不敢更新版本了。javascript
可是,研究了这么久,放弃太惋惜,唉,只能抱着相信尤大大能将 weex 打形成 vue 同样的想法一直走下去。vue
1.weex 默认适配尺寸java
weex
默认使用750px * 1334px
做为适配尺寸, 实际渲染时因为浮点数的偏差可能会存在几px
的偏差, 出现细线等样式问题, 能够经过加减几个px
来调试webpack
注:style上须要添加 scoped,不然没法自动适配。web
2.navigator 页面跳转vue-router
示例一:weex
<script> var navigator = weex.requireModule('navigator') var modal = weex.requireModule('modal') export default { methods: { jump (event) { console.log('will jump') navigator.push({ url: 'http://dotwe.org/raw/dist/519962541fcf6acd911986357ad9c2ed.js', animated: "true" }, event => { modal.toast({ message: 'callback: ' + event }) }) } } }; </script>
示例二:ui
function isWeex () { return process.env.COMPILE_ENV === 'weex' // 须要在webpack中自定义 } export default { methods: { push (path) { if (isWeex()) { const toUrl = weex.config.bundleUrl.split('/').slice(0, -1).join('/') + '/' + path + '.js' // 将a.js的绝对地址转为b.js的绝对地址 weex.requireModule('navigator').push({ url: toUrl, animated: 'true' }) } else { this.$router.push(path) // 使用vue-router } }, pop () { if (isWeex()) { weex.requireModule('navigator').pop({ animated: 'true' }) } else { window.history.back() } } } }
.this