Weex入门(一)

2017-03-01  本文已影响21人  a2ebcc3676c1

一、搭建Node.js环境

1、安装node的常见方法有两种

2、两种方法的区别

3、安装HomeBrew

ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
    - cd `brew --prefix`
    - rm -rf Cellar$ brew prune
    - rm -rf Library .git .gitignore bin/brew README.md share/man/man1/brew
    - rm -rf ~/Library/Caches/Homebrew  
    //如果没有权限,指令前加sudo

4、安装Node.js

5、使用 npm 来安装 weex-toolkit

国内开发者可以考虑使用淘宝的 npm 镜像cnpm

$ npm install -g cnpm
$ cnpm install -g weex-toolkit@beta
sudo cnpm install -g weex-toolkit@beta
$ weex

Usage: weex <foo/bar/we_file_or_dir_path>  [options]
Usage: weex init [projectName]

选项:
  --port    http listening port number ,default is 8081           [默认值: 8081]
  --wsport  websocket listening port number ,default is 8082      [默认值: 8082]
  --output  to build the js bundle to the specify a path
                                                  [默认值: "no JSBundle output"]

Usage:weex <command>

where <command> is one of:

       debug               start weex debugger
       compile             compile we/vue file
       run                 run your project

weex  <command> --help      help on <command>

二、初始化项目(与官网一致)

1、初始化项目

$ weex init awesome-project

2、安装项目依赖

npm install --unsafe-perm=true

3、开启watch 模式

npm run dev

4、开启静态服务器

npm run serve

5、在浏览器中查看

 http://localhost:8080/index.html

6、我们可以在src/foo.vue中改写代码

<template>
  <div class="wrapper">
    <text class="weex">Hello Weex !</text>
    <text class="vue">Hello Vue !</text>
  </div>
</template>
<style scoped>
  .wrapper {
    flex-direction: column;
    justify-content: center;
  }
  .weex {
   font-size: 60px;
   text-align: center;
   color: #1B90F7;
  }
  .vue {
   font-size: 60px;
   text-align: center;
   margin-top: 30px;
   color: #41B883;
  }
</style>

三、运行结果

运行结果 log
上一篇 下一篇

猜你喜欢

热点阅读