1.一旦数据和模板绑定,数据的变化会立即体现在前台的变化

  1. <template>
  2. <container>
  3. <text style="font-size: {{size}}">{{title}}</text>
  4. </container>
  5. </template>
  6.  
  7. <script>
  8. module.exports = {
  9. data: {
  10. size: 48,
  11. title: 'Alibaba Weex Team'
  12. }
  13. }
  14. </script>
  1. <template>
  2. <container>
  3. <text style="font-size: {{title.size}}">{{title.value}}</text>
  4. </container>
  5. </template>
  6.  
  7. <script>
  8. module.exports = {
  9. data: {
  10. title: {
  11. size: 48,
  12. value: 'Alibaba Weex Team'
  13. }
  14. }
  15. }
  16. </script>

2.样式类

  1. <template>
  2. <container>
  3. <text style="font-size: {{fontSize}};">Alibaba</text>
  4. <text class="large {{textClass}}">Weex Team</text>
  5. </container>
  6. </template>
  7. <style>
  8. .large {font-size: 32;}
  9. .highlight {color: #ff0000;}
  10. </style>
  11. <script>
  12. module.exports = {
  13. data: {
  14. fontSize: 32,
  15. textClass: 'highlight'
  16. }
  17. }
  18. </script>

3.事件

  1. <template>
  2. <container>
  3. <text onclick="toggle">Toggle</text>
  4. <image class="thumb" src="http://alibaba.github.io/weex/img/weex_logo_blue@3x.png" if="{{shown}}"></image>
  5. </container>
  6. </template>
  7.  
  8. <script>
  9. module.exports = {
  10. data: {
  11. shown: true
  12. },
  13. methods: {
  14. toggle: function () {
  15. this.shown = !this.shown
  16. }
  17. }
  18. }
  19. </script>
  20.  
  21. <style>
  22. .thumb { width: 100; height: 100; }
  23. </style>
  1. <template>
  2. <scroller>
  3. <wxc-panel title="Toast" type="primary">
  4. <wxc-button type="primary" onclick="{{toast}}" value="Toast"></wxc-button>
  5. </wxc-panel>
  6.  
  7. <wxc-panel title="Dialog" type="primary">
  8. <wxc-button type="success" onclick="{{alert}}" value="Alert" style="margin-bottom: 20px;"></wxc-button>
  9. <wxc-button type="primary" onclick="{{confirm}}" value="Confirm" style="margin-bottom: 20px;"></wxc-button>
  10. <wxc-button type="warning" onclick="{{prompt}}" value="Prompt"></wxc-button>
  11. </wxc-panel>
  12. </scroller>
  13. </template>
  14.  
  15. <script>
  16. require('weex-components');
  17. module.exports = {
  18. data: {},
  19. methods: {
  20. toast: function(msg, duration) {
  21. if (!msg || typeof msg !== 'string') {
  22. msg = 'I am Toast show!';
  23. }
  24.  
  25. duration = duration || 2;
  26. this.$call('modal', 'toast', {
  27. 'message': msg,
  28. 'duration': duration
  29. });
  30. },
  31. alert: function(msg, okTitle, cancelTitle) {
  32. var self = this;
  33. if (!msg || typeof msg !== 'string') {
  34. msg = "I am Alert!";
  35. }
  36. this.$call('modal', 'alert', {
  37. 'message': msg,
  38. 'okTitle': okTitle,
  39. 'cancelTitle': cancelTitle
  40. }, function() {
  41. self.toast("Click Alert OK Bnt!!");
  42. });
  43. },
  44. confirm: function(msg, okTitle, cancelTitle) {
  45. var self = this
  46. if (!msg || typeof msg !== 'string') {
  47. msg = "I am Confirm!";
  48. }
  49.  
  50. okTitle = okTitle || "OK";
  51. cancelTitle = cancelTitle || "Cancel";
  52. this.$call('modal', 'confirm', {
  53. 'message': msg,
  54. 'okTitle': okTitle,
  55. 'cancelTitle': cancelTitle
  56. }, function(result) {
  57. self.toast("Click Confirm " + result);
  58. });
  59. },
  60. prompt: function() {
  61. var self = this;
  62. this.$call('modal', 'prompt', {
  63. 'message': 'I am Prompt!',
  64. 'okTitle': 'ok',
  65. 'cancelTitle': 'cancel'
  66. }, function(result) {
  67. self.toast("Click Prompt " + result);
  68. });
  69. }
  70. }
  71. }
  72. </script>
  73.  
  74. <style>
  75. </style>

效果图

4.动画

  1. <template>
  2. <div>
  3. <wxc-panel title="Transform" type="primary">
  4. <wxc-button value="Rotate" onclick="{{rotate}}" type="primary" size="middle"></wxc-button>
  5. <wxc-button value="Scale" onclick="{{scale}}" type="primary" size="middle" style="margin-top:12px;"></wxc-button>
  6. <wxc-button value="Translate" onclick="{{translate}}" type="primary" size="middle"
  7. style="margin-top:12px;"></wxc-button>
  8. <wxc-button value="Transform" onclick="{{transform}}" type="success" size="middle"
  9. style="margin-top:12px;"></wxc-button>
  10. </wxc-panel>
  11.  
  12. <wxc-panel title="Others" type="primary">
  13. <wxc-button value="BgColor" onclick="{{color}}" type="primary" size="middle"></wxc-button>
  14. <wxc-button value="Opacity" onclick="{{opacity}}" type="primary" size="middle"
  15. style="margin-top:12px;"></wxc-button>
  16. <wxc-button value="All" onclick="{{composite}}" type="success" size="middle" style="margin-top:12px;"></wxc-button>
  17. </wxc-panel>
  18.  
  19. <div id="block" class="block" style="transform-origin:{{transformOrigin}}">
  20. <text class="block-txt">Anim</text>
  21. </div>
  22. </div>
  23. </template>
  24.  
  25. <script>
  26. require('weex-components');
  27. module.exports = {
  28. data: {
  29. transformOrigin: 'center center',
  30. current_rotate: 0,
  31. current_scale: 1,
  32. current_color: '#FF0000',
  33. current_opacity: 1,
  34. current_translate: '',
  35. current_transform: '',
  36. isStop: true
  37. },
  38. methods: {
  39. anim: function(styles, timingFunction, duration, callback) {
  40. this.$call('animation', 'transition', this._ids.block.el.ref, {
  41. styles: styles,
  42. timingFunction: timingFunction,
  43. duration: duration
  44. }, callback);
  45. },
  46. rotate: function() {
  47. var self = this;
  48. self.current_rotate += 90;
  49. self.anim({
  50. transform: 'rotate(' + self.current_rotate + 'deg)'
  51. }, 'ease-in-out', 500, function() {
  52. if (self.current_rotate === 360) {
  53. self.current_rotate = 0;
  54. }
  55. else {
  56. self.rotate();
  57. }
  58. });
  59. },
  60. translate: function() {
  61. this.current_translate = this.current_translate ? '' : 'translate(50%, 50%)';
  62. this.anim({
  63. transform: this.current_translate
  64. }, 'ease-in', 500, function() {
  65. });
  66. },
  67. scale: function() {
  68. var self = this;
  69. self.current_scale = self.current_scale === 2 ? .5 : 2
  70. self.anim({
  71. transform: 'scale(' + self.current_scale + ')'
  72. }, 'linear', 500, function() {
  73. });
  74. },
  75. transform: function() {
  76. var self = this;
  77. this.current_transform = this.current_transform ? '' : 'rotate(45deg) scale(1.5)';
  78. this.anim({
  79. transform: this.current_transform,
  80. transformOrigin: 'left top'
  81. }, 'ease-out', 500, function() {
  82. if (self.current_transform !== '') {
  83. self.anim({
  84. transform: 'rotate(-90deg) scale(1.2)',
  85. transformOrigin: 'left top'
  86. }, 'ease-out', 500, function() {
  87. })
  88. }
  89. else {
  90.  
  91. }
  92. });
  93. },
  94. composite: function() {
  95. var self = this;
  96. self.current_transform = self.current_transform ? '' : 'rotate(45deg) scale(1.5) translate(50%, 50%)';
  97. self.current_color = self.current_color === '#F0AD4E' ? '#D9534F' : '#F0AD4E';
  98. self.current_opacity = self.current_opacity === 1 ? 0.1 : 1;
  99. this.anim({
  100. transform: this.current_transform,
  101. transformOrigin: 'left top',
  102. backgroundColor: self.current_color,
  103. opacity: self.current_opacity
  104. }, 'ease-out', 1000, function() {
  105. });
  106. },
  107. color: function() {
  108. var self = this;
  109. self.current_color = self.current_color === '#F0AD4E' ? '#D9534F' : '#F0AD4E';
  110. self.anim({
  111. backgroundColor: self.current_color
  112. }, 'linear', 500, function() {
  113. });
  114. },
  115. opacity: function() {
  116. var self = this;
  117. self.current_opacity = self.current_opacity === 1 ? 0.1 : 1;
  118. self.anim({
  119. opacity: self.current_opacity
  120. }, 'linear', 500, function() {
  121. });
  122. }
  123. }
  124. };
  125. </script>
  126.  
  127. <style>
  128. .block {
  129. position: absolute;
  130. width: 250px;
  131. height: 250px;
  132. top: 300px;
  133. left: 400px;
  134. background-color: #F0AD4E;
  135. align-items: center;
  136. justify-content: center;
  137. }
  138.  
  139. .block-txt {
  140. color: #FFFFFF;
  141. font-size: 70px;
  142. }
  143. </style>

Weex 初始的更多相关文章

  1. weex中UISegmentControl实现及遇到的问题

    在最近主导的一个项目中,App端的实现使用了weex.通过近一个月的实践,我们发现如果对于人机交互较少的App,即使较少前端经验的人也能迅速进入开发(当然需要一定时间 才能上手weex).在开发的时候 ...

  2. Weex 解析(二)—— NativeBridge

    (本篇幅主要讲解Weex 中iOS native与js交互实现) 大纲: weex 总框架预览 iOS NativeBridge总设计原理 一.weex 总框架预览 在写NativeBridge 总设 ...

  3. weex手机端安全键盘

    github地址:weexSafeKeyboard 效果图: 技术依赖:框架:weex+vue 弹出层:weex-ui 图标:iconfont 说明:1.如果不想用到weex-ui,可以把inputk ...

  4. 2DToolkit官方文档中文版打地鼠教程(一):初始设置

    这是2DToolkit官方文档中 Whack a Mole 打地鼠教程的译文,为了减少文中过多重复操作的翻译,以及一些无必要的句子,这里我假设你有Unity的基础知识(例如了解如何新建Sprite等) ...

  5. ReactNative&weex&DeviceOne对比

    React Native出来有一段时间了,国内的weex和deviceone是近期发布的,我可以说从2011年就开始关注快速开发的跨平台平台技术了,接触过phoneGap.数字天堂.appcan等早期 ...

  6. CSharpGL(38)带初始数据创建Vertex Buffer Object的情形汇总

    CSharpGL(38)带初始数据创建Vertex Buffer Object的情形汇总 开始 总的来说,OpenGL应用开发者会遇到为如下三种数据创建Vertex Buffer Object的情形: ...

  7. 阿里的weex框架到底是什么

    title: 阿里的weex框架到底是什么 date: 2016-09-27 10:22:34 tags: vue, weex category: 技术总结 --- weex 工作原理 首先看下官方的 ...

  8. ArrayList、Vector、HashMap、HashSet的默认初始容量、加载因子、扩容增量

    当底层实现涉及到扩容时,容器或重新分配一段更大的连续内存(如果是离散分配则不需要重新分配,离散分配都是插入新元素时动态分配内存),要将容器原来的数据全部复制到新的内存上,这无疑使效率大大降低. 加载因 ...

  9. linux系统下使用xampp 丢失mysql root密码【xampp的初始密码为空】

    如果在ubuntu 下面 使用xampp这个集成开发环境,却忘记mysql密码. 注:刚安装好的xampp的Mysql初始密码是空... 找回密码的步骤如下: 1.停止mysql服务器 sudo /o ...

随机推荐

  1. JQUERY 插件开发——LAZYLOADIMG(预加载和延迟加载图片)

    开发背景 本插件开发是近期写的最后一个插件了,接下来我想把最近研究的redis最为一个系列阐述下.当然Jquery插件开发是我个人爱好,我不会停止,在将来的开发中我会继续完善,当然也会坚持写这个系列的 ...

  2. [BZOJ 2594] [Wc2006]水管局长数据加强版 【LCT】

    题目链接:BZOJ - 2594 题目分析 这道题如果没有删边的操作,那么就是 NOIP2013 货车运输,求两点之间的一条路径,使得边权最大的边的边权尽量小. 那么,这条路径就是最小生成树上这两点之 ...

  3. Google提议使用Jsonnet来增强JSON

    Google开源了一门配置语言Jsonnet来取代JSON,它完全向后兼容并加入了一些新特性:注释.引用.算术运算.条件操作符,数组和对象内含,引入,函数,局部变量,继承等.Jsonnet程序被翻译为 ...

  4. Qt中事件处理的方法(图文并茂,仔细看看)

    http://blog.csdn.net/qing666888/article/details/14111271 http://blog.csdn.net/qing666888/article/det ...

  5. Weblogic8.1 的性能优化

    注:在下面做的介绍都是以Weblogic8.1为例的,其它版本的Weblogic可能会有些许不同. 1) 设置JAVA参数: a) 编辑Weblogic Server启动脚本文件: BEA_HOMEu ...

  6. 【转】iOS开发Xcode7真机调试教程

    原文网址:https://www.skyfox.org/ios-xcode7-debug-device.html 从Xcode7开始,Xcode 不需要$99/$299升级开发者直接可以进行真机调试 ...

  7. Linux学习笔记20——第一个多线程程序

    一 什么是线程 线程:是一个进程内部的一个控制序列. 二 使用POSIX的注意点 1 为了使用线程函数库,必须定义宏_REENTRANT,通过定义_REENTRANT来告诉编译器我们需要可重入功能,可 ...

  8. [QT]构建正则表达式测试

    正则表达式是个强大的东西 暂时先记录一个用法: QString str = "Peak memory: KEY s"; QString data = "Peak memo ...

  9. VS2010 MFC GDI+ 实现PNG透明图片显示

    网上找了一些资料学习了一下PNG图的显示,这里总结一下. 参考:http://blog.csdn.net/czyt1988/article/details/7965066 一.VS2010配置GDI+ ...

  10. 细谈Java

    重载:相同函数名,不同参数. 重写(覆写):父类和子类之间的,子类重写了父类的方法. java的多态:重载+覆写 1.      Main方法: 是public的,也是static,也是void的,参 ...