├── .gitignore ├── LICENSE ├── README.md ├── SUMMARY.md ├── _book ├── LICENSE ├── gitbook │ ├── app.js │ ├── fonts │ │ └── fontawesome │ │ │ ├── FontAwesome.otf │ │ │ ├── fontawesome-webfont.eot │ │ │ ├── fontawesome-webfont.svg │ │ │ ├── fontawesome-webfont.ttf │ │ │ └── fontawesome-webfont.woff │ ├── images │ │ ├── apple-touch-icon-precomposed-152.png │ │ └── favicon.ico │ ├── print.css │ └── style.css ├── index.html ├── search_index.json ├── 常见问题 │ ├── h5如何发布和部署.html │ ├── index.html │ └── 如何获取url上面的参数.html ├── 环境搭建 │ ├── index.html │ ├── 各种依赖.html │ ├── 线上调试.html │ └── 项目脚手架.html ├── 示例 │ └── index.html ├── 组件库 │ └── index.html ├── 编码标准 │ ├── index.html │ ├── 样式.html │ ├── 模板.html │ └── 脚本.html └── 语法介绍 │ ├── html模板.html │ ├── index.html │ ├── script脚本.html │ └── style样式.html ├── book.json ├── 常见问题 ├── README.md ├── h5如何发布和部署.md └── 如何获取url上面的参数.md ├── 环境搭建 ├── README.md ├── 各种依赖.md ├── 线上调试.md └── 项目脚手架.md ├── 示例 └── README.md ├── 组件库 └── README.md ├── 编码标准 ├── README.md ├── 样式.md ├── 模板.md └── 脚本.md └── 语法介绍 ├── README.md ├── html模板.md ├── script脚本.md └── style样式.md /.gitignore: -------------------------------------------------------------------------------- 1 | # Logs 2 | logs 3 | *.log 4 | npm-debug.log* 5 | 6 | # Runtime data 7 | pids 8 | *.pid 9 | *.seed 10 | 11 | # Directory for instrumented libs generated by jscoverage/JSCover 12 | lib-cov 13 | 14 | # Coverage directory used by tools like istanbul 15 | coverage 16 | 17 | # nyc test coverage 18 | .nyc_output 19 | 20 | # Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files) 21 | .grunt 22 | 23 | # node-waf configuration 24 | .lock-wscript 25 | 26 | # Compiled binary addons (http://nodejs.org/api/addons.html) 27 | build/Release 28 | 29 | # Dependency directories 30 | node_modules 31 | jspm_packages 32 | 33 | # Optional npm cache directory 34 | .npm 35 | 36 | # Optional REPL history 37 | .node_repl_history 38 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2016 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # h5weex-books 2 | 3 | > h5weex开发相关文章 4 | 5 | #### 主要内容: 6 | 7 | - 1、环境搭建 8 | - 2、语法介绍 9 | - 3、编码标准 10 | - 4、组件库 11 | - 5、示例 12 | - 6、常见问题 13 | -------------------------------------------------------------------------------- /SUMMARY.md: -------------------------------------------------------------------------------- 1 | Summary of my h5 weex book. 2 | 3 | * [环境搭建](环境搭建/README.md) 4 | * [各种依赖](环境搭建/各种依赖.md) 5 | * [项目脚手架](环境搭建/项目脚手架.md) 6 | * [线上调试](环境搭建/线上调试.md) 7 | * [语法介绍](语法介绍/README.md) 8 | * [html模板](语法介绍/html模板.md) 9 | * [style样式](语法介绍/style样式.md) 10 | * [script脚本](语法介绍/script脚本.md) 11 | * [编码标准](编码标准/README.md) 12 | * [模板](编码标准/模板.md) 13 | * [样式](编码标准/样式.md) 14 | * [脚本](编码标准/脚本.md) 15 | * [组件库](组件库/README.md) 16 | * [示例](示例/README.md) 17 | * [常见问题](常见问题/README.md) 18 | * [h5如何发布和部署](常见问题/h5如何发布和部署.md) 19 | * [如何获取url上面的参数](常见问题/如何获取url上面的参数.md) 20 | -------------------------------------------------------------------------------- /_book/LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2016 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /_book/gitbook/fonts/fontawesome/FontAwesome.otf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/h5weex/h5weex-books/0f47ae18af25d64bb5ced70f44b0ba9ab4c3c262/_book/gitbook/fonts/fontawesome/FontAwesome.otf -------------------------------------------------------------------------------- /_book/gitbook/fonts/fontawesome/fontawesome-webfont.eot: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/h5weex/h5weex-books/0f47ae18af25d64bb5ced70f44b0ba9ab4c3c262/_book/gitbook/fonts/fontawesome/fontawesome-webfont.eot -------------------------------------------------------------------------------- /_book/gitbook/fonts/fontawesome/fontawesome-webfont.ttf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/h5weex/h5weex-books/0f47ae18af25d64bb5ced70f44b0ba9ab4c3c262/_book/gitbook/fonts/fontawesome/fontawesome-webfont.ttf -------------------------------------------------------------------------------- /_book/gitbook/fonts/fontawesome/fontawesome-webfont.woff: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/h5weex/h5weex-books/0f47ae18af25d64bb5ced70f44b0ba9ab4c3c262/_book/gitbook/fonts/fontawesome/fontawesome-webfont.woff -------------------------------------------------------------------------------- /_book/gitbook/images/apple-touch-icon-precomposed-152.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/h5weex/h5weex-books/0f47ae18af25d64bb5ced70f44b0ba9ab4c3c262/_book/gitbook/images/apple-touch-icon-precomposed-152.png -------------------------------------------------------------------------------- /_book/gitbook/images/favicon.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/h5weex/h5weex-books/0f47ae18af25d64bb5ced70f44b0ba9ab4c3c262/_book/gitbook/images/favicon.ico -------------------------------------------------------------------------------- /_book/gitbook/print.css: -------------------------------------------------------------------------------- 1 | .link-inherit{color:inherit}.link-inherit:hover,.link-inherit:focus{color:inherit}.hidden{display:none}.hljs-comment,.hljs-title{color:#8e908c}.hljs-variable,.hljs-attribute,.hljs-tag,.hljs-regexp,.ruby .hljs-constant,.xml .hljs-tag .hljs-title,.xml .hljs-pi,.xml .hljs-doctype,.html .hljs-doctype,.css .hljs-id,.css .hljs-class,.css .hljs-pseudo{color:#c82829}.hljs-number,.hljs-preprocessor,.hljs-pragma,.hljs-built_in,.hljs-literal,.hljs-params,.hljs-constant{color:#f5871f}.ruby .hljs-class .hljs-title,.css .hljs-rules .hljs-attribute{color:#eab700}.hljs-string,.hljs-value,.hljs-inheritance,.hljs-header,.ruby .hljs-symbol,.xml .hljs-cdata{color:#718c00}.css .hljs-hexcolor{color:#3e999f}.hljs-function,.python .hljs-decorator,.python .hljs-title,.ruby .hljs-function .hljs-title,.ruby .hljs-title .hljs-keyword,.perl .hljs-sub,.javascript .hljs-title,.coffeescript .hljs-title{color:#4271ae}.hljs-keyword,.javascript .hljs-function{color:#8959a8}.hljs{display:block;background:white;color:#4d4d4c;padding:.5em}.coffeescript .javascript,.javascript .xml,.tex .hljs-formula,.xml .javascript,.xml .vbscript,.xml .css,.xml .hljs-cdata{opacity:.5}.page.page-toc .glossary{margin-bottom:40px}.page.page-toc .glossary h2 a,.page.page-toc .glossary h2 a:hover{color:inherit;text-decoration:none}.page.page-toc .glossary .glossary-index{list-style:none;margin:0;padding:0}.page.page-toc .glossary .glossary-index li{display:inline;margin:0 8px;white-space:nowrap}.page .book-chapter{display:none}body .page{font-family:sans-serif;-ms-text-size-adjust:100%;-webkit-text-size-adjust:100%;line-height:1.4;color:#333;overflow:hidden;line-height:1.6;word-wrap:break-word;display:block}body .page>*:first-child{margin-top:0!important}body .page>*:last-child{margin-bottom:0!important}body .page a{background:transparent}body .page a:active,body .page a:hover{outline:0}body .page strong{font-weight:bold}body .page h1{font-size:2em;margin:.67em 0}body .page img{border:0}body .page hr{-moz-box-sizing:content-box;box-sizing:content-box;height:0}body .page pre{overflow:auto}body .page code,body .page pre{font-family:monospace,monospace;font-size:1em;direction:ltr}body .page table{border-collapse:collapse;border-spacing:0}body .page td,body .page th{padding:0}body .page *{-moz-box-sizing:border-box;box-sizing:border-box}body .page a{color:#4183c4;text-decoration:none}body .page a:hover,body .page a:focus,body .page a:active{text-decoration:underline}body .page hr{height:0;margin:15px 0;overflow:hidden;background:transparent;border:0;border-bottom:1px solid #ddd}body .page hr:before,body .page hr:after{display:table;content:" "}body .page hr:after{clear:both}body .page h1,body .page h2,body .page h3,body .page h4,body .page h5,body .page h6{margin-top:15px;margin-bottom:15px;line-height:1.1}body .page h1{font-size:30px}body .page h2{font-size:21px}body .page h3{font-size:16px}body .page h4{font-size:14px}body .page h5{font-size:12px}body .page h6{font-size:11px}body .page blockquote{margin:0}body .page ul,body .page ol{padding:0;margin-top:0;margin-bottom:0}body .page ol ol{list-style-type:lower-roman}body .page dd{margin-left:0}body .page code,body .page pre{font-family:Consolas,"Liberation Mono",Menlo,Courier,monospace;font-size:12px}body .page pre{margin-top:0;margin-bottom:0}body .page .markdown-body>*:first-child{margin-top:0!important}body .page .markdown-body>*:last-child{margin-bottom:0!important}body .page .anchor{position:absolute;top:0;bottom:0;left:0;display:block;padding-right:6px;padding-left:30px;margin-left:-30px}body .page .anchor:focus{outline:0}body .page h1,body .page h2,body .page h3,body .page h4,body .page h5,body .page h6{position:relative;margin-top:1em;margin-bottom:16px;font-weight:bold;line-height:1.4}body .page h1{padding-bottom:.3em;font-size:2.25em;line-height:1.2;border-bottom:1px solid #eee}body .page h2{padding-bottom:.3em;font-size:1.75em;line-height:1.225;border-bottom:1px solid #eee}body .page h3{font-size:1.5em;line-height:1.43}body .page h4{font-size:1.25em}body .page h5{font-size:1em}body .page h6{font-size:1em;color:#777}body .page p,body .page blockquote,body .page ul,body .page ol,body .page dl,body .page table,body .page pre{margin-top:0;margin-bottom:16px}body .page hr{height:4px;padding:0;margin:16px 0;background-color:#e7e7e7;border:0 none}body .page ul,body .page ol{padding-left:2em}body .page ol ol,body .page ol ul,body .page ul ul{margin-top:0;margin-bottom:0}body .page dl{padding:0}body .page dl dt{padding:0;margin-top:16px;font-size:1em;font-style:italic;font-weight:bold}body .page dl dd{padding:0 16px;margin-bottom:16px}body .page blockquote{padding:0 15px;color:#777;border-left:4px solid #ddd}body .page blockquote>:first-child{margin-top:0}body .page blockquote>:last-child{margin-bottom:0}body .page table{display:block;width:100%;overflow:auto}body .page table th{font-weight:bold}body .page table th,body .page table td{padding:6px 13px;border:1px solid #ddd}body .page table tr{background-color:#fff;border-top:1px solid #ccc}body .page table tr:nth-child(2n){background-color:#f8f8f8}body .page img{max-width:100%;-moz-box-sizing:border-box;box-sizing:border-box;page-break-inside:avoid}body .page code{padding:0;padding-top:.2em;padding-bottom:.2em;margin:0;font-size:85%;background-color:#f7f7f7;border-radius:3px}body .page code:before,body .page code:after{letter-spacing:-0.2em;content:"\00a0"}body .page pre>code{padding:0;margin:0;font-size:100%;white-space:pre;background:transparent;border:0}body .page .highlight pre,body .page pre{padding:16px;overflow:auto;font-size:85%;line-height:1.45;background-color:#f7f7f7;border:0;border-radius:3px}body .page pre{word-wrap:normal}body .page pre code{display:inline;max-width:initial;padding:0;margin:0;overflow:initial;line-height:inherit;word-wrap:normal;background-color:transparent;border:0}body .page pre code:before,body .page pre code:after{content:normal}body .page .highlight{background:#fff} -------------------------------------------------------------------------------- /_book/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 |
5 | 6 | 7 | 8 |446 |448 |h5weex开发相关文章
447 |
this.$getConfig()
,通过该方法是可以获取URL上的参数,代码如下:/**
450 | * 获取URL参数
451 | */
452 | getUrlParam: function (key) {
453 | var t = this.$getConfig().bundleUrl;
454 | var reg = new RegExp('[?|&]' + key + '=([^&]+)');
455 | var match = t.match(reg);
456 | return match && match[1];
457 | }
458 |
459 |
460 | 先讲下本地如何调试:
448 |ctrl+alt+t
,也可进入调试;线上调试有点麻烦,需要你的APP支持weex才行,下面以手淘
举例:
weex-toolkit
,并且保证更新到最新版:npm install -g weex-toolkit
;weex debug
;chrome devtool
;所有的示例会在这里定义,请访问:https://github.com/h5weex/h5weex-example
448 | 449 | 450 |所有的组件会在这里定义,请访问:https://github.com/h5weex/h5weex-components
448 | 449 | 450 |先看一个标准的模板代码:
448 |<template>
449 | <div data-role="recommend_itemlist">
450 | <div class="wrapper" if="{{mds.itemList.length}}">
451 | <div repeat="{{mds.itemList}}" url="{{url}}" class="item-url" onclick="goTargetUrl">
452 | <image src="{{pic_url}}" class="item-img"></image>
453 | <div class="item-info">
454 | <div class="item-price">
455 | <text class="item-price-text">¥</text>
456 | <text class="item-price-text big">{{price.split('.')[0]}}</text>
457 | <text class="item-price-text">{{price.split('.').length > 1 ? '.' + price.split('.')[1] : ''}}</text>
458 | </div>
459 | </div>
460 | </div>
461 | </div>
462 | </div>
463 | </template>
464 |
.editorconfig
文件,自己根据喜好定义缩进是2个空格还是4个空格class
来定义样式,避免class
和style
混用的情况;class
名采用短线来连接,不是驼峰式和下划线连接;先看一个标准的脚本定义代码:
448 |<script>
449 | module.exports = {
450 | data: {
451 | mds: {
452 | dataParams: {
453 | "catId": "-1"
454 | }
455 | },
456 | gdc: {
457 | "ownerId": 2202220535
458 | }
459 | },
460 | methods: {
461 | goTargetUrl: function(e) {
462 | require('@weex-module/event').openURL(e.target.attr.url);
463 | },
464 |
465 | render: function(ds, gd){
466 | var vm = this;
467 | if(ds){ vm.mds = ds; }
468 | if(gd){ vm.gdc = gd; }
469 | }
470 | },
471 | created: function () {
472 | console.log('page created');
473 | },
474 | ready: function () {
475 | console.log('page ready');
476 | }
477 | };
478 | </script>
479 |
render
方法,保证可以传数据,实现懒加载;created
方法中用来定义动态数据的获取;reday
方法常用来上报,不要在这里面获取数据,会导致页面重新渲染,消耗性能;标准的weex程序包含三个部分,如下:
448 |<template>
449 | <!-- (required) the structure of page -->
450 | </template>
451 |
452 | <style>
453 | /* (optional) stylesheet */
454 | </style>
455 |
456 | <script>
457 | /* (optional) the definition of data, methods and life-circle */
458 | </script>
459 |
先看一个hello world
的实现:
<template>
449 | <container>
450 | <text>{{myname}}</text>
451 | </container>
452 | </template>
453 |
454 | <script>
455 | module.exports = {
456 | data: {
457 | "myname": "hello world"
458 | },
459 | methods: {
460 | render: function(ds) {
461 | this.myname = ds;
462 | }
463 | },
464 | created: function () {
465 |
466 | },
467 | ready: function () {
468 |
469 | }
470 | };
471 | </script>
472 |
<script>
标签来包含你的脚本;module.exports
这个对象中;data
里面是定义的数据对象,可以通过this.xxx
获取,在模板中是通过``来获取;methods
对象中用来定义自己的函数;created
是生命周期函数,这个时候模板还没有被渲染,常用来在这里定义数据的更新和获取;ready
是生命周期函数,这个时候模板被渲染,常用来做一些自己上报等;