Weex 是一套简单易用的跨平台开发方案,能以 web 的开发体验构建高性能、可扩展的 native 应用,为了做到这些,Weex 与 Vue 合作,使用 Vue 作为上层框架,并遵循 W3C 标准实现了统一的 JSEngine 和 DOM API,这样一来,你甚至可以使用其他框架驱动 Weex,打造三端一致的 native 应用。
首先,安装node.js和weex-toolkit
对于Mac系统,可以用homebrew进行安装:
$ brew install node
安装后,验证是否安装成功:
$ node -v
v7.2.1
$ npm -v
3.10.9
然后,我们安装weex-toolkit
$ npm install -g weex-toolkit
国内开发者可以考虑使用淘宝源
$ npm install -g cnpm
$ cnpm install -g weex-toolkit
$touch hello.we
<template>
<div>
<text class="text" style="color: #FF0000;">Hello world</text>
</div>
</template>
<style>
.text{
font-size: 50;
}
</style>
<script>
</script>
编译运行:
$ weex hello.we
已经在浏览器中看到了刚才的代码效果,为了验证三端是否一致,我们还需 Playground App 验证。这里,我们需要为 weex hello.we 增加 --qr 参数,表示生成二维码。
$ weex hello.we --qr
然后,使用 Playground 扫码即可。
$ weex debug hello.we