Weex项目创建

4 篇文章 0 订阅

1、环境安装

安装Node.js

安装npm

2、创建weex项目

2.1、全局安装  weex-toolkit

npm install weex-toolkit -g

2.2、初始化项目(项目名全部小写)

weex create 项目名

weex create weex-app

2.3、进入目录,安装依赖

cd weex-app

npm install

2.4、启动项目,访问

npm start

http://localhost:8081:访问Web端效果页面

页面结构同Vue,页面源码在  src 目录下

同时可以访问 http://localhost:8081/web/preview.html ,页面内嵌 iframe 模拟移动端效果展示

Preview

3、weex  Web H5打包

3.1、安装 weexpack 

npm install -g weexpack

3.2、对已有项目进行打包H5

weexpack build web

本地预览Web    项目/release/web/index.html

4、上传github

  • 添加 .gitignore 文件,移除node_modules/文件夹上传git
node_modules/
  • 将项目下的 web文件夹中的 assets/ 和 preview.html添加到 release/ 下,使得本地预览正常 目录结构

release

assets
web
preview.html

  • 修改preview.html内容
<iframe id="preview" src="./web/index.html" frameborder="0"></iframe>

访问 项目/release/preview.html

5、项目页面结构

这里以Vue单文件组件为例   *.vue文件

template:

<template>
  <text class="message">Weex Vue demo222</text>
</template>

script:

<script>
module.exports = {
    data: function() {
        return {
        	content: 'weex'
        }
    }
}
</script>

style: 可以使用 CSS预处理工具

<style lang="less" scoped>
@color: red;

.message {
    color: @color;
}
</style>
<template>
    <text class="message">Weex Vue demo222</text>
</template>
<script>
module.exports = {
    data: function() {
        return {
        	content: 'weex'
        }
    }
}
</script>
<style lang="less" scoped>
@color: red;

.message {
    color: @color;
}
</style>

页面入口 src/index.vue(类似App.vue)

路由配置 src/router.js

 

 

 

 

 

 

 

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值