当前位置:   article > 正文

微信小程序-入门_glass-easel weui

glass-easel weui

一.通过   Npm方式下载构建

1.下载和安装NpmNpm    https://docs.npmjs.com/downloading-and-installing-node-js-and-npm

                    或者     https://nodejs.org/en/download/ 

未安装npm 提示

           以下以安装node安装包为例

 

 

 

 

 

按任意键继续

 

安装完成后 

2. 下载和安装小程序开发工具  :https://developers.weixin.qq.com/miniprogram/dev/devtools/download.html
 3.安装使用weui 

https://github.com/wechat-miniprogram/weui-miniprogram

3.1  在小程序根目录下初始化npm

 按以下方式避免npm初始化报错

  1. message: NPM packages not found. Please confirm npm packages which need to build are belong to `miniprogramRoot` directory. Or you may edit project.config.json's `packNpmManually` and `packNpmRelationList`
  2. appid: wxfdcdeefd46e93725
  3. openid: o6zAJs4UHtxoUdwBMYwoYl2bQM9Y
  4. ideVersion: 1.06.2401020
  5. osType: win32-x64
  6. time: 2024-03-07 14:31:03

 

 根目录下初始化

 npm init  -y

 

 安装npm

npm  install 

配置project.config.json文件

  1. "packNpmManually": true,
  2. "packNpmRelationList": [
  3. {
  4. "packageJsonPath": "./package.json",
  5. "miniprogramNpmDistDir": "./miniprogram/"
  6. }
  7. ],

 安装小程序weui npm包

npm install --save weui-miniprogram

 

 重新打开此项目

 打开工具菜单=>构建npm

二.通过   useExtendedLib扩展库方式下载构建 

  1.通过微信开发者工具创建项目

  2.配置项目根目录下app.json,添加如下内容:
  1. "useExtendedLib": {
  2. "weui": true
  3. },

  3.以官网-progress 进度条实例为例:

      编辑index目录下 index.js

  1. const app = getApp()
  2. Page({
  3. data: {
  4. },
  5. onLoad: function () {
  6. console.log('代码片段是一种迷你、可分享的小程序或小游戏项目,可用于分享小程序和小游戏的开发经验、展示组件和 API 的使用、复现开发问题和 Bug 等。可点击以下链接查看代码片段的详细文档:')
  7. console.log('https://mp.weixin.qq.com/debug/wxadoc/dev/devtools/devtools.html')
  8. },
  9. })

   

  编辑index目录下 index.wxml

  1. <progress percent="20" show-info />
  2. <progress percent="40" stroke-width="12" />
  3. <progress percent="60" color="pink" />
  4. <progress percent="80" active />
  5. <progress percent="100" active />

 编辑index目录下 index.wxml

  1. progress {margin: 10px;}

 编译运行即可

  4.以官网-checkbox实例为例:

  编辑index目录下 index.js

  1. Page({
  2. data: {
  3. items: [
  4. { name: 'USA', value: '美国' },
  5. { name: 'CHN', value: '中国', checked: 'true' },
  6. { name: 'BRA', value: '巴西' },
  7. { name: 'JPN', value: '日本' },
  8. { name: 'ENG', value: '英国' },
  9. { name: 'TUR', value: '法国' },
  10. ]
  11. },
  12. checkboxChange: function (e) {
  13. console.log('checkbox发生change事件,携带value值为:', e.detail.value)
  14. }
  15. })

  编辑index目录下 index.json

{ "componentFramework": "glass-easel" }

  编辑index目录下 index.wxml

  1. <checkbox-group bindchange="checkboxChange">
  2. <label class="checkbox" wx:for="{{items}}">
  3. <checkbox value="{{item.name}}" checked="{{item.checked}}"/>{{item.value}}
  4. </label>
  5. </checkbox-group>

  编辑index目录下 index.wxss

  1. .intro {
  2. margin: 30px;
  3. text-align: center;
  4. }
  5. page {
  6. margin-top: 80px;
  7. }
  8. .checkbox, checkbox {
  9. display: flex;
  10. flex-direction: row;
  11. height: 30px;
  12. line-height: 30px;
  13. }
  14. .checkbox {
  15. justify-content: center;
  16. }

 编译预览

  5.以官网-input实例为例:

  编辑index目录下 index.js

  1. Page({
  2. data: {
  3. focus: false,
  4. inputValue: '',
  5. placeholderStyle: {color:'#F76260'}
  6. },
  7. onLoad() {
  8. // 兼容
  9. console.log(this.renderer)
  10. if (this.renderer == 'skyline') {
  11. this.setData({
  12. placeholderStyle: {color:'#F76260'}
  13. })
  14. } else {
  15. this.setData({
  16. placeholderStyle: "color:#F76260"
  17. })
  18. }
  19. },
  20. bindKeyInput: function (e) {
  21. this.setData({
  22. inputValue: e.detail.value
  23. })
  24. },
  25. bindReplaceInput: function (e) {
  26. var value = e.detail.value
  27. var pos = e.detail.cursor
  28. var left
  29. if (pos !== -1) {
  30. // 光标在中间
  31. left = e.detail.value.slice(0, pos)
  32. // 计算光标的位置
  33. pos = left.replace(/11/g, '2').length
  34. }
  35. // 直接返回对象,可以对输入进行过滤处理,同时可以控制光标的位置
  36. return {
  37. value: value.replace(/11/g, '2'),
  38. cursor: pos
  39. }
  40. // 或者直接返回字符串,光标在最后边
  41. // return value.replace(/11/g,'2'),
  42. },
  43. bindHideKeyboard: function (e) {
  44. if (e.detail.value === '123') {
  45. // 收起键盘
  46. wx.hideKeyboard()
  47. }
  48. }
  49. })

  编辑index目录下 index.js

{ "componentFramework": "glass-easel" }

  编辑index目录下 index.wxml

  1. <view class="page-body">
  2. <view class="page-section">
  3. <view class="weui-cells__title">可以自动聚焦的input</view>
  4. <view class="weui-cells weui-cells_after-title">
  5. <view class="weui-cell weui-cell_input">
  6. <input class="weui-input" auto-focus placeholder="将会获取焦点"/>
  7. </view>
  8. </view>
  9. </view>
  10. <view class="page-section">
  11. <view class="weui-cells__title">控制最大输入长度的input</view>
  12. <view class="weui-cells weui-cells_after-title">
  13. <view class="weui-cell weui-cell_input">
  14. <input class="weui-input" maxlength="10" placeholder="最大输入长度为10" />
  15. </view>
  16. </view>
  17. </view>
  18. <view class="page-section">
  19. <view class="weui-cells__title">实时获取输入值:{{inputValue}}</view>
  20. <view class="weui-cells weui-cells_after-title">
  21. <view class="weui-cell weui-cell_input">
  22. <input class="weui-input" maxlength="10" bindinput="bindKeyInput" placeholder="输入同步到view中"/>
  23. </view>
  24. </view>
  25. </view>
  26. <view class="page-section">
  27. <view class="weui-cells__title">控制输入的input</view>
  28. <view class="weui-cells weui-cells_after-title">
  29. <view class="weui-cell weui-cell_input">
  30. <input class="weui-input" bindinput="bindReplaceInput" placeholder="连续的两个1会变成2" />
  31. </view>
  32. </view>
  33. </view>
  34. <view class="page-section">
  35. <view class="weui-cells__title">控制键盘的input</view>
  36. <view class="weui-cells weui-cells_after-title">
  37. <view class="weui-cell weui-cell_input">
  38. <input class="weui-input" bindinput="bindHideKeyboard" placeholder="输入123自动收起键盘" />
  39. </view>
  40. </view>
  41. </view>
  42. <view class="page-section">
  43. <view class="weui-cells__title">数字输入的input</view>
  44. <view class="weui-cells weui-cells_after-title">
  45. <view class="weui-cell weui-cell_input">
  46. <input class="weui-input" type="number" placeholder="这是一个数字输入框" />
  47. </view>
  48. </view>
  49. </view>
  50. <view class="page-section">
  51. <view class="weui-cells__title">密码输入的input</view>
  52. <view class="weui-cells weui-cells_after-title">
  53. <view class="weui-cell weui-cell_input">
  54. <input class="weui-input" password type="text" placeholder="这是一个密码输入框" />
  55. </view>
  56. </view>
  57. </view>
  58. <view class="page-section">
  59. <view class="weui-cells__title">带小数点的input</view>
  60. <view class="weui-cells weui-cells_after-title">
  61. <view class="weui-cell weui-cell_input">
  62. <input class="weui-input" type="digit" placeholder="带小数点的数字键盘"/>
  63. </view>
  64. </view>
  65. </view>
  66. <view class="page-section">
  67. <view class="weui-cells__title">身份证输入的input</view>
  68. <view class="weui-cells weui-cells_after-title">
  69. <view class="weui-cell weui-cell_input">
  70. <input class="weui-input" type="idcard" placeholder="身份证输入键盘" />
  71. </view>
  72. </view>
  73. </view>
  74. <view class="page-section">
  75. <view class="weui-cells__title">控制占位符颜色的input</view>
  76. <view class="weui-cells weui-cells_after-title">
  77. <view class="weui-cell weui-cell_input">
  78. <input class="weui-input" placeholder-style="{{placeholderStyle}}" placeholder="占位符字体是红色的" />
  79. </view>
  80. </view>
  81. </view>
  82. </view>

  1. .page-body {
  2. margin-top: 80px;
  3. }
  4. .page-section{
  5. margin-bottom: 20rpx;
  6. }
  7. .weui-input {
  8. width: 100%;
  9. height: 44px;
  10. line-height: 44px;
  11. }

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/花生_TL007/article/detail/370700
推荐阅读
相关标签
  

闽ICP备14008679号