这次WeUI 1.0由于命名规范发生了巨大改变,因此在这里列出一些代码的改动点,希望对大家有所帮助:

关于命名

由之前单一的下划线改成weui-aaa__bbb-bbb_ccc-ccc这种形式,横杠为连词符,双下划线区分Block和Element(BEM),单下划线连接Modify。下面列出几个例子:

Old New
weui_cells weui-cells
weui_cell_bd weui-cell__bd
weui_btn_primary weui-btn_primary
weui_btn_plain_primary weui-btn_plain-primary

button

除了命名以外,其它改变不大。

cell

之前必须显示定义weui_cell_primary来规定撑满的是hd,bd还是ft。现在默认是bd来撑满,weui-cell_primary变成实现顶部对齐的扩展类。

Old

  1. <div class="weui_cell">
  2. <div class="weui_cell_hd"></div>
  3. <div class="weui_cell_bd weui_cell_primary">...</div>
  4. <div class="weui_cell_ft"></div>
  5. </div>

New

  1. <div class="weui-cell">
  2. <div class="weui-cell__hd"></div>
  3. <div class="weui-cell__bd">...</div>
  4. <div class="weui-cell__ft"></div>
  5. </div>

带验证码的输入框,img必须定义weui-vcode-img的类名

Old

  1. <div class="weui_cell weui_vcode">
  2. <div class="weui_cell_ft">
  3. <img src="./images/vcode.jpg">
  4. </div>
  5. </div>

New

  1. <div class="weui-cell weui-cell_vcode">
  2. <div class="weui-cell__ft">
  3. <img class="weui-vcode-img" src="./images/vcode.jpg">
  4. </div>
  5. </div>

带箭头的列表,由之前的weui_cells_access改为单独控制的weui-cell_access

Old

  1. <div class="weui_cells weui_cells_access">
  2. <a class="weui_cell">...</a>
  3. </div>

New

  1. <div class="weui-cells">
  2. <a class="weui-cell weui-cell_access">...</a>
  3. </div>

uploader

头部以前是嵌套cell来实现左右布局。新版是用了新类名来实现:

Old

  1. <div class="weui_uploader">
  2. <div class="weui_uploader_hd weui_cell">
  3. <div class="weui_cell_bd weui_cell_primary">图片上传</div>
  4. <div class="weui_cell_ft">0/2</div>
  5. </div>
  6. </div>

New

  1. <div class="weui-uploader">
  2. <div class="weui-uploader__hd">
  3. <p class="weui-uploader__title">图片上传</p>
  4. <div class="weui-uploader__info">0/2</div>
  5. </div>
  6. </div>
Old New
weui_uploader_status weui-uploader__file_status
weui_uploader_status_content weui-uploader__file-content
weui_uploader_input_wrp weui-uploader__input-box

loading

Old

  1. <div class="weui_loading">
  2. <div class="weui_loading_leaf weui_loading_leaf_0"></div>
  3. <div class="weui_loading_leaf weui_loading_leaf_1"></div>
  4. <div class="weui_loading_leaf weui_loading_leaf_2"></div>
  5. <div class="weui_loading_leaf weui_loading_leaf_3"></div>
  6. <div class="weui_loading_leaf weui_loading_leaf_4"></div>
  7. <div class="weui_loading_leaf weui_loading_leaf_5"></div>
  8. <div class="weui_loading_leaf weui_loading_leaf_6"></div>
  9. <div class="weui_loading_leaf weui_loading_leaf_7"></div>
  10. <div class="weui_loading_leaf weui_loading_leaf_8"></div>
  11. <div class="weui_loading_leaf weui_loading_leaf_9"></div>
  12. <div class="weui_loading_leaf weui_loading_leaf_10"></div>
  13. <div class="weui_loading_leaf weui_loading_leaf_11"></div>
  14. </div>

New

  1. <i class="weui-loading weui-icon_toast"></i>

panel:

  • 所有的weui_media都改成了weui-media-box
  • 去掉了weui_panel_access
Old New
weui_search_outer weui-search-bar__form
weui_search_inner weui-search-bar__box
weui_search_text weui-search-bar__label
weui_search_cancel weui-search-bar__cancel-btn

tab

  • 去掉了weui_tab_bd_item_active,以前这个类只是实现display:block而已,新版本就去掉了。

dialog

Old

  1. <div class="weui-dialog__ft">
  2. <a href="javascript:;" class="weui-dialog__btn weui-dialog__btn_default">辅助操作</a>
  3. <a href="javascript:;" class="weui-dialog__btn weui-dialog__btn_primary">主操作</a>
  4. </div>

New

  1. <div class="weui-dialog__ft">
  2. <a href="javascript:;" class="weui-dialog__btn weui-dialog__btn_default">辅助操作</a>
  3. <a href="javascript:;" class="weui-dialog__btn weui-dialog__btn_primary">主操作</a>
  4. </div>

toptips

Old

  1. <div class="weui_toptips weui_warn"></div>

New

  1. <div class="weui-toptips weui-toptips_warn"></div>

另外,若想看老版本的代码和DEMO:https://github.com/weui/weui/releases/tag/v0.4.3老版本的DEMO在dist/example/index.html。

原文: https://github.com/Tencent/weui/wiki/%E5%9C%A81.0.0%E5%9C%A8%E4%BB%A3%E7%A0%81%E5%B1%82%E9%9D%A2%E4%B8%8A%E5%81%9A%E4%BA%86%E5%93%AA%E4%BA%9B%E6%94%B9%E5%8F%98