当前位置:   article > 正文

微信小程序基础代码_微信小程序代码大全

微信小程序代码大全

                             微信小程序基础代码

可以使用 Visual Studio Code 开发微信小程序,看个人喜好了;

安装插件小程序开发助手

安装插件Easy Less 后支持 less样式开发

还需要配置下才支持less

添加:

  1. "less.compile": {
  2. "outExt": ".wxcss"
  3. }

1.

2.

 

3.

 

一.基础代码 wxml

  1. <!--
  2. 1 text 相当于以前web中的 span标签 行内元素 不会换行
  3. 2 view 相当于以前web中的 div标签 块级元素 会换行
  4. 3 checkbox 以前的复选框标签
  5. -->
  6. <!-- <text>1</text>
  7. <text>2</text>
  8. <view>1</view>
  9. <view>2</view> -->
  10. <!-- 1 字符串 -->
  11. <view> {{msg}} </view>
  12. <!-- 2 数字类型 -->
  13. <view>{{num}}</view>
  14. <!-- 3 bool类型 -->
  15. <view> 是否是伪娘: {{isGirl}} </view>
  16. <!-- 4 object类型 -->
  17. <view>{{person.age}}</view>
  18. <view>{{person.height}}</view>
  19. <view>{{person.weight}}</view>
  20. <view>{{person.name}}</view>
  21. <!-- 5 在标签的属性中使用 -->
  22. <view data-num="{{num}}"> 自定义属性</view>
  23. <!--
  24. 6 使用bool类型充当属性 checked
  25. 1 字符串和 花括号之间一定不要存在空格 否则会导致识别失败
  26. 以下写法就是错误的示范
  27. <checkbox checked=" {{isChecked}}"> </checkbox>
  28. -->
  29. <view>
  30. <checkbox checked="{{isChecked}}"> </checkbox>
  31. </view>
  32. <!--
  33. 7 运算 => 表达式
  34. 1 可以在花括号中 加入 表达式 -- “语句”
  35. 2 表达式
  36. 指的是一些简单 运算 数字运算 字符串 拼接 逻辑运算。。
  37. 1 数字的加减。。
  38. 2 字符串拼接
  39. 3 三元表达式
  40. 3 语句
  41. 1 复杂的代码段
  42. 1 if else
  43. 2 switch
  44. 3 do while 。。。。
  45. 4 for 。。。
  46. -->
  47. <view>{{1+1}}</view>
  48. <view>{{'1'+'1'}}</view>
  49. <view>{{ 11%2===0 ? '偶数' : '奇数' }}</view>
  50. <!--
  51. 8 列表循环
  52. 1 wx:for="{{数组或者对象}}" wx:for-item="循环项的名称" wx:for-index="循环项的索引"
  53. 2 wx:key="唯一的值" 用来提高列表渲染的性能
  54. 1 wx:key 绑定一个普通的字符串的时候 那么这个字符串名称 肯定是 循环数组 中的 对象的 唯一属性
  55. 2 wx:key ="*this" 就表示 你的数组 是一个普通的数组 *this 表示是 循环项
  56. [1,2,3,44,5]
  57. ["1","222","adfdf"]
  58. 3 当出现 数组的嵌套循环的时候 尤其要注意 以下绑定的名称 不要重名
  59. wx:for-item="item" wx:for-index="index"
  60. 4 默认情况下 我们 不写
  61. wx:for-item="item" wx:for-index="index"
  62. 小程序也会把 循环项的名称 和 索引的名称 item 和 index
  63. 只有一层循环的话 (wx:for-item="item" wx:for-index="index") 可以省略
  64. 9 对象循环
  65. 1 wx:for="{{对象}}" wx:for-item="对象的值" wx:for-index="对象的属性"
  66. 2 循环对象的时候 最好把 item和index的名称都修改一下
  67. wx:for-item="value" wx:for-index="key"
  68. -->
  69. <view>
  70. <view
  71. wx:for="{{list}}"
  72. wx:for-item="item"
  73. wx:for-index="index"
  74. wx:key="id"
  75. >
  76. 索引:{{index}}
  77. --
  78. 值:{{item.name}}
  79. </view>
  80. </view>
  81. <view>
  82. <view>对象循环</view>
  83. <view
  84. wx:for="{{person}}"
  85. wx:for-item="value"
  86. wx:for-index="key"
  87. wx:key="age"
  88. >
  89. 属性:{{key}}
  90. --
  91. 值:{{value}}
  92. </view>
  93. </view>
  94. <!--
  95. 10 block
  96. 1 占位符的标签
  97. 2 写代码的时候 可以看到这标签存在
  98. 3 页面渲染 小程序会把它移除掉
  99. -->
  100. <view>
  101. <block
  102. wx:for="{{list}}"
  103. wx:for-item="item"
  104. wx:for-index="index"
  105. wx:key="id"
  106. class="my_list"
  107. >
  108. 索引:{{index}}
  109. --
  110. 值:{{item.name}}
  111. </block>
  112. </view>
  113. <!--
  114. 11 条件渲染
  115. 1 wx:if="{{true/false}}"
  116. 1 if , else , if else
  117. wx:if
  118. wx:elif
  119. wx:else
  120. 2 hidden
  121. 1 在标签上直接加入属性 hidden
  122. 2 hidden="{{true}}"
  123. 3 什么场景下用哪个
  124. 1 当标签不是频繁的切换显示 优先使用 wx:if
  125. 直接把标签从 页面结构给移除掉
  126. 2 当标签频繁的切换显示的时候 优先使用 hidden
  127. 通过添加样式的方式来切换显示
  128. hidden 属性 不要和 样式 display一起使用
  129. -->
  130. <view>
  131. <view>条件渲染</view>
  132. <view wx:if="{{true}}">显示</view>
  133. <view wx:if="{{false}}">隐藏</view>
  134. <view wx:if="{{flase}}">1</view>
  135. <view wx:elif="{{flase}}">2 </view>
  136. <view wx:else> 3 </view>
  137. <view>---------------</view>
  138. <view hidden >hidden1</view>
  139. <view hidden="{{false}}" >hidden2</view>
  140. <view>-----000-------</view>
  141. <view wx:if="{{false}}">wx:if</view>
  142. <view hidden style="display: flex;" >hidden</view>
  143. </view>

js

  1. //Page Object
  2. Page({
  3. data: {
  4. msg: "hello mina",
  5. num: 10000,
  6. isGirl: false,
  7. person: {
  8. age: 74,
  9. height: 145,
  10. weight: 200,
  11. name: "富婆"
  12. },
  13. isChecked:false,
  14. list:[
  15. {
  16. id:0,
  17. name:"猪八戒"
  18. },
  19. {
  20. id:1,
  21. name:"天蓬元帅"
  22. },
  23. {
  24. id:2,
  25. name:"悟能"
  26. }
  27. ]
  28. }
  29. });

 

 

 

二.事件及数据绑定  wxml

  1. <!--
  2. 1 需要给input标签绑定 input事件
  3. 绑定关键字 bindinput
  4. 2 如何获取 输入框的值
  5. 通过事件源对象来获取
  6. e.detail.value
  7. 3 把输入框的值 赋值到 data当中
  8. 不能直接
  9. 1 this.data.num=e.detail.value
  10. 2 this.num=e.detail.value
  11. 正确的写法
  12. this.setData({
  13. num:e.detail.value
  14. })
  15. 4 需要加入一个点击事件
  16. 1 bindtap
  17. 2 无法在小程序当中的 事件中 直接传参
  18. 3 通过自定义属性的方式来传递参数 data-operation="{{1}} js中 const operation = e.currentTarget.dataset.operation;
  19. 4 事件源中获取 自定义属性
  20. -->
  21. <input type="text" bindinput="handleInput" />
  22. <button bindtap="handletap" data-operation="{{1}}" >+</button>
  23. <button bindtap="handletap" data-operation="{{-1}}">-</button>
  24. <view>
  25. {{num}}
  26. </view>

js

  1. // pages/demo04/demo04.js
  2. Page({
  3. data: {
  4. num: 0
  5. },
  6. // 输入框的input事件的执行逻辑
  7. handleInput(e) {
  8. // console.log(e.detail.value );
  9. this.setData({
  10. num: e.detail.value
  11. })
  12. },
  13. // 加 减 按钮的事件
  14. handletap(e) {
  15. // console.log(e);
  16. // 1 获取自定义属性 operation 中的数据
  17. const operation = e.currentTarget.dataset.operation;
  18. this.setData({
  19. num: this.data.num + operation
  20. })
  21. }
  22. })

 

三.  分辨率 rpx wxml

  1. <view>
  2. rpx
  3. </view>

 

wxss

1 存在一个设计稿 宽度 414 或者 未知 page 
  1 设计稿 page 存在一个元素 宽度 100px
  2 拿以上的需求 去实现 不同宽度的页面适配 

  page px = 750 rpx
  1 px = 750 rpx / page
  100 px = 750 rpx * 100 / page 
  假设 设备是苹果6 分辨率  page =  375px
2 利用 一个属性 calc属性  css 和 wxss 都支持 一个属性
  1 750 和 rpx 中间不要留空格
  2 运算符的两边也不要留空格

  /* 以下代码写法是错误  */
  /*  width:750 rpx * 100 / 375 ;  */

 

正确:

假设 设备是苹果6 分辨率375  page =  375px

view{
   width:calc(750rpx * 100 / 375);
   height: 200rpx;
   font-size: 40rpx;
   background-color: aqua;
 }

  1. /*
  2. 1 小程序中 不需要主动来引入样式文件
  3. 2 需要把页面中某些元素的单位 由 px 改成 rpx
  4. 1 设计稿 750x
  5. 750 px = 750 rpx
  6. 1 px = 1 rpx
  7. 2 把屏幕宽度 改成 375px
  8. 375 px = 750 rpx
  9. 1 px = 2rpx
  10. 1rpx = 0.5px
  11. 3 存在一个设计稿 宽度 414 或者 未知 page
  12. 1 设计稿 page 存在一个元素 宽度 100px
  13. 2 拿以上的需求 去实现 不同宽度的页面适配
  14. page px = 750 rpx
  15. 1 px = 750 rpx / page
  16. 100 px = 750 rpx * 100 / page
  17. 假设 page = 375px
  18. 4 利用 一个属性 calc属性 css 和 wxss 都支持 一个属性
  19. 1 750 和 rpx 中间不要留空格
  20. 2 运算符的两边也不要留空格
  21. */
  22. view{
  23. /* width: 200rpx; */
  24. height: 200rpx;
  25. font-size: 40rpx;
  26. background-color: aqua;
  27. /* 以下代码写法是错误 */
  28. /* width:750 rpx * 100 / 375 ; */
  29. width:calc(750rpx * 100 / 375);
  30. }

 wxss 引入

1.工程目录下创建 样式文件夹mini-01\styles

2.创建样式文件

common.wxss

  1. view{
  2. color: aqua;
  3. font-size: 100px;
  4. }

 wxss

  1. /*
  2. 1 引入的 代码 是通过 @import 来引入
  3. 2 路径 只能写相对路径
  4. */
  5. @import "../../styles/common.wxss";

 

 

四.  

 wxss

  1. /* 1 定义less变量 */
  2. text {
  3. /* 2 使用变量 */
  4. color: yellow;
  5. }
  6. view .vie1 text {
  7. color: red;
  8. }
  9. /* 导入 */
  10. view {
  11. color: green;
  12. }
  13. .main {
  14. /*
  15. 1 less中 支持 两种注释 多行 单行
  16. 2 wxss 不能写 单行注释 因为 写了 和没写是一样!!!
  17. */
  18. /* font-size: 200px; */
  19. }

less

  1. /* 1 定义less变量 */
  2. @color:yellow;
  3. text{
  4. /* 2 使用变量 */
  5. color:@color;
  6. }
  7. view{
  8. .vie1{
  9. text{
  10. color: red;
  11. }
  12. }
  13. }
  14. /* 导入 */
  15. @import "../../styles/reset.less";
  16. view{
  17. color: @themeColor;
  18. }
  19. .main{
  20. /*
  21. 1 less中 支持 两种注释 多行 单行
  22. 2 wxss 不能写 单行注释 因为 写了 和没写是一样!!!
  23. */
  24. /* font-size: 200px; */
  25. // font-size: 400px;
  26. }

 

reset.less

@themeColor:green;
 

五.  长按文字复制,对文本内容 进行 解码  wxml

  1. <!--
  2. 1 长按文字复制 selectable
  3. 2 对文本内容 进行 解码
  4. -->
  5. <text selectable decode>
  6. text &nbsp; 123 &lt;
  7. </text>
uploading.4e448015.gif转存失败 重新上传 取消

js

  1. // pages/demo08/demo08.js
  2. Page({
  3. /**
  4. * 页面的初始数据
  5. */
  6. data: {
  7. },
  8. /**
  9. * 生命周期函数--监听页面加载
  10. */
  11. onLoad: function (options) {
  12. },
  13. /**
  14. * 生命周期函数--监听页面初次渲染完成
  15. */
  16. onReady: function () {
  17. },
  18. /**
  19. * 生命周期函数--监听页面显示
  20. */
  21. onShow: function () {
  22. },
  23. /**
  24. * 生命周期函数--监听页面隐藏
  25. */
  26. onHide: function () {
  27. },
  28. /**
  29. * 生命周期函数--监听页面卸载
  30. */
  31. onUnload: function () {
  32. },
  33. /**
  34. * 页面相关事件处理函数--监听用户下拉动作
  35. */
  36. onPullDownRefresh: function () {
  37. },
  38. /**
  39. * 页面上拉触底事件的处理函数
  40. */
  41. onReachBottom: function () {
  42. },
  43. /**
  44. * 用户点击右上角分享
  45. */
  46. onShareAppMessage: function () {
  47. }
  48. })
uploading.4e448015.gif转存失败 重新上传 取消

六.  图片 wxml

  1. <!--
  2. image 图片标签
  3. 1 src 指定要加载的图片的路径
  4. 图片存在默认的宽度和高度 320 * 240 原图大小是 200 * 100
  5. 2 mode 决定 图片内容 如何 和 图片标签 宽高 做适配
  6. 1 scaleToFill 默认值 不保持纵横比缩放图片,使图片的宽高完全拉伸至填满 image 元素
  7. 2 aspectFit 保持宽高比 确保图片的长边 显示出来 页面轮播图 常用
  8. 3 aspectFill 保持纵横比缩放图片,只保证图片的 短 边能完全显示出来。 少用
  9. 4 widthFix 以前web的图片的 宽度指定了之后 高度 会自己按比例来调整 常用
  10. 5 bottom。。 类似以前的backgroud-position
  11. 3 小程序当中的图片 直接就支持 懒加载 lazy-load
  12. 1 lazy-load 会自己判断 当 图片 出现在 视口 上下 三屏的高度 之内的时候 自己开始加载图片
  13. -->
  14. <image mode="bottom" lazy-load src="https://tva2.sinaimg.cn/large/007DFXDhgy1g51jlzfb4lj305k02s0sp.jpg" />
uploading.4e448015.gif转存失败 重新上传 取消

 

wxss

  1. image{
  2.   box-sizing: border-box;
  3.   border: 1px solid red;
  4.   width: 300px;
  5.   height: 200px;
  6. }

七. 轮播图  wxml

  1. <!--
  2. 1 轮播图外层容器 swiper
  3. 2 每一个轮播项 swiper-item
  4. 3 swiper标签 存在默认样式
  5. 1 width 100%
  6. 2 height 150px image 存在默认宽度和高度 320 * 240
  7. 3 swiper 高度 无法实现由内容撑开
  8. 4 先找出来 原图的宽度和高度 等比例 给swiper 定 宽度和高度
  9. 原图的宽度和高度 1125 * 352 px
  10. swiper 宽度 / swiper 高度 = 原图的宽度 / 原图的高度
  11. swiper 高度 = swiper 宽度 * 原图的高度 / 原图的宽度
  12. height: 100vw * 352 / 1125
  13. 5 autoplay 自动轮播
  14. 6 interval 修改轮播时间
  15. 7 circular 衔接轮播
  16. 8 indicator-dots 显示 指示器 分页器 索引器
  17. 9 indicator-color 指示器的未选择的颜色
  18. 10 indicator-active-color 选中的时候的指示器的颜色
  19. -->
  20. <swiper autoplay interval="1000" circular indicator-dots indicator-color="#0094ff" indicator-active-color="#ff0094">
  21. <swiper-item> <image mode="widthFix" src="//gw.alicdn.com/imgextra/i1/44/O1CN013zKZP11CCByG5bAeF_!!44-0-lubanu.jpg" /> </swiper-item>
  22. <swiper-item> <image mode="widthFix" src="//aecpm.alicdn.com/simba/img/TB1CWf9KpXXXXbuXpXXSutbFXXX.jpg_q50.jpg" /> </swiper-item>
  23. <swiper-item> <image mode="widthFix" src="//gw.alicdn.com/imgextra/i2/37/O1CN01syHZxs1C8zCFJj97b_!!37-0-lubanu.jpg" /> </swiper-item>
  24. </swiper>
uploading.4e448015.gif转存失败 重新上传 取消

 

八.  页面 跳转wxml

  1. <!--
  2. 导航组件 navigator
  3. 0 块级元素 默认会换行 可以直接加宽度和高度
  4. 1 url 要跳转的页面路径 绝对路径 相对路径
  5. 2 target 要跳转到当前的小程序 还是其他的小程序的页面
  6. self 默认值 自己 小程序的页面
  7. miniProgram 其他的小程序的页面
  8. 3 open-type 跳转的方式
  9. 1 navigate 默认值 保留当前页面,跳转到应用内的某个页面,但是不能跳到 tabbar 页面
  10. 2 redirect 关闭当前页面,跳转到应用内的某个页面,但是不允许跳转到 tabbar 页面。
  11. 3 switchTab 跳转到 tabBar 页面,并关闭其他所有非 tabBar 页面
  12. 4 reLaunch 关闭所有页面,打开到应用内的某个页面
  13. -->
  14. <navigator url="/pages/demo10/demo10"> 轮播图页面 </navigator>
  15. <navigator url="/pages/index/index"> 直接跳转到 tabbar页面 </navigator>
  16. <navigator open-type="redirect" url="/pages/demo10/demo10"> 轮播图页面 redirect </navigator>
  17. <navigator open-type="switchTab" url="/pages/index/index"> switchTab直接跳转到 tabbar页面 </navigator>
  18. <navigator open-type="reLaunch" url="/pages/index/index"> reLaunch 可以随便跳 </navigator>
uploading.4e448015.gif转存失败 重新上传 取消

 

九.   富文本标签 wxml

  1. <!--
  2. rich-text 富文本标签
  3. 1 nodes属性来实现
  4. 1 接收标签字符串
  5. 2 接收对象数组
  6. -->
  7. <rich-text nodes="{{html}}"></rich-text>
uploading.4e448015.gif转存失败 重新上传 取消

js

  1. // pages/demo12/demo12.js
  2. Page({
  3. data: {
  4. // 1 标签字符串 最常用的
  5. // html:'<div class="tpl-wrapper" data-tpl-id="m_h_v31icon_1" style="margin-top: -10px;"><div view-name="DFrameLayout" style="display: flex; overflow: hidden; height: 160px; width: 375px; place-self: flex-start; position: relative;"><div view-name="DView" style="display: flex; overflow: hidden; background-color: rgb(255, 255, 255); margin-top: 9px; height: 100%; width: 100%; top: 0px; left: 0px; position: absolute;"></div><div view-name="HImageView" style="display: flex; overflow: hidden; height: 100%; width: 100%; position: absolute;"><div style="width: 100%; height: 100%; background-image: url(&quot;https://gw.alicdn.com/tps/TB155AUPpXXXXajXVXXXXXXXXXX-1125-480.png_.webp&quot;); background-repeat: no-repeat; background-position: center center; background-size: contain;"></div></div><div view-name="DLinearLayout" aria-label="天猫" style="display: flex; overflow: hidden; width: 61px; height: 67px; margin-left: 10px; margin-top: 13px; -webkit-box-orient: vertical; flex-direction: column; top: 0px; left: 0px; position: absolute;"><div view-name="HGifView" style="display: flex; overflow: hidden; width: 61px; height: 48px;"><div style="width: 100%; height: 100%; background-repeat: no-repeat; background-position: center center; background-size: contain; background-image: url(&quot;https://gw.alicdn.com/tfs/TB1Wxi2trsrBKNjSZFpXXcXhFXa-183-144.png_.webp&quot;);"></div></div><div view-name="DTextView" style="display: inline-block; overflow: hidden; font-size: 11px; height: auto; margin-top: 5px; text-align: center; color: rgb(102, 102, 102); width: 61px; text-overflow: ellipsis; white-space: nowrap; line-height: 14px;">天猫</div></div><div view-name="DLinearLayout" aria-label="聚划算" style="display: flex; overflow: hidden; width: 61px; height: 67px; margin-left: 83.5px; margin-top: 13px; -webkit-box-orient: vertical; flex-direction: column; top: 0px; left: 0px; position: absolute;"><div view-name="HGifView" style="display: flex; overflow: hidden; width: 61px; height: 48px;"><div style="width: 100%; height: 100%; background-repeat: no-repeat; background-position: center center; background-size: contain; background-image: url(&quot;https://img.alicdn.com/tfs/TB10UHQaNjaK1RjSZKzXXXVwXXa-183-144.png?getAvatar=1_.webp&quot;);"></div></div><div view-name="DTextView" style="display: inline-block; overflow: hidden; font-size: 11px; height: auto; margin-top: 5px; text-align: center; color: rgb(102, 102, 102); width: 61px; text-overflow: ellipsis; white-space: nowrap; line-height: 14px;">聚划算</div></div><div view-name="DLinearLayout" aria-label="天猫国际" style="display: flex; overflow: hidden; width: 61px; height: 67px; margin-left: 157px; margin-top: 13px; -webkit-box-orient: vertical; flex-direction: column; top: 0px; left: 0px; position: absolute;"><div view-name="HGifView" style="display: flex; overflow: hidden; width: 61px; height: 48px;"><div style="width: 100%; height: 100%; background-repeat: no-repeat; background-position: center center; background-size: contain; background-image: url(&quot;https://gw.alicdn.com/tfs/TB11rTqtj7nBKNjSZLeXXbxCFXa-183-144.png?getAvatar=1_.webp&quot;);"></div></div><div view-name="DTextView" style="display: inline-block; overflow: hidden; font-size: 11px; height: auto; margin-top: 5px; text-align: center; color: rgb(102, 102, 102); width: 61px; text-overflow: ellipsis; white-space: nowrap; line-height: 14px;">天猫国际</div></div><div view-name="DLinearLayout" aria-label="外卖" style="display: flex; overflow: hidden; width: 61px; height: 67px; margin-left: 230.5px; margin-top: 13px; -webkit-box-orient: vertical; flex-direction: column; top: 0px; left: 0px; position: absolute;"><div view-name="HGifView" style="display: flex; overflow: hidden; width: 61px; height: 48px;"><div style="width: 100%; height: 100%; background-repeat: no-repeat; background-position: center center; background-size: contain; background-image: url(&quot;https://gw.alicdn.com/tps/TB1eXc7PFXXXXb4XpXXXXXXXXXX-183-144.png?getAvatar=1_.webp&quot;);"></div></div><div view-name="DTextView" style="display: inline-block; overflow: hidden; font-size: 11px; height: auto; margin-top: 5px; text-align: center; color: rgb(102, 102, 102); width: 61px; text-overflow: ellipsis; white-space: nowrap; line-height: 14px;">外卖</div></div><div view-name="DLinearLayout" aria-label="天猫超市" style="display: flex; overflow: hidden; width: 61px; height: 67px; margin-left: 304px; margin-top: 13px; -webkit-box-orient: vertical; flex-direction: column; top: 0px; left: 0px; position: absolute;"><div view-name="HGifView" style="display: flex; overflow: hidden; width: 61px; height: 48px;"><div style="width: 100%; height: 100%; background-repeat: no-repeat; background-position: center center; background-size: contain; background-image: url(&quot;https://gw.alicdn.com/tfs/TB1IKqDtpooBKNjSZFPXXXa2XXa-183-144.png_.webp&quot;);"></div></div><div view-name="DTextView" style="display: inline-block; overflow: hidden; font-size: 11px; height: auto; margin-top: 5px; text-align: center; color: rgb(102, 102, 102); width: 61px; text-overflow: ellipsis; white-space: nowrap; line-height: 14px;">天猫超市</div></div><div view-name="DLinearLayout" aria-label="充值中心" style="display: flex; overflow: hidden; width: 61px; height: 67px; margin-left: 10px; margin-top: 84px; -webkit-box-orient: vertical; flex-direction: column; top: 0px; left: 0px; position: absolute;"><div view-name="HGifView" style="display: flex; overflow: hidden; width: 61px; height: 48px;"><div style="width: 100%; height: 100%; background-repeat: no-repeat; background-position: center center; background-size: contain; background-image: url(&quot;https://gw.alicdn.com/tfs/TB1o0FLtyMnBKNjSZFoXXbOSFXa-183-144.png_.webp&quot;);"></div></div><div view-name="DTextView" style="display: inline-block; overflow: hidden; font-size: 11px; height: auto; margin-top: 5px; text-align: center; color: rgb(102, 102, 102); width: 61px; text-overflow: ellipsis; white-space: nowrap; line-height: 14px;">充值中心</div></div><div view-name="DLinearLayout" aria-label="飞猪旅行" style="display: flex; overflow: hidden; width: 61px; height: 67px; margin-left: 83.5px; margin-top: 84px; -webkit-box-orient: vertical; flex-direction: column; top: 0px; left: 0px; position: absolute;"><div view-name="HGifView" style="display: flex; overflow: hidden; width: 61px; height: 48px;"><div style="width: 100%; height: 100%; background-repeat: no-repeat; background-position: center center; background-size: contain; background-image: url(&quot;https://gw.alicdn.com/tfs/TB15nKhtpkoBKNjSZFEXXbrEVXa-183-144.png?getAvatar=1_.webp&quot;);"></div></div><div view-name="DTextView" style="display: inline-block; overflow: hidden; font-size: 11px; height: auto; margin-top: 5px; text-align: center; color: rgb(102, 102, 102); width: 61px; text-overflow: ellipsis; white-space: nowrap; line-height: 14px;">飞猪旅行</div></div><div view-name="DLinearLayout" aria-label="领金币" style="display: flex; overflow: hidden; width: 61px; height: 67px; margin-left: 157px; margin-top: 84px; -webkit-box-orient: vertical; flex-direction: column; top: 0px; left: 0px; position: absolute;"><div view-name="HGifView" style="display: flex; overflow: hidden; width: 61px; height: 48px;"><div style="width: 100%; height: 100%; background-repeat: no-repeat; background-position: center center; background-size: contain; background-image: url(&quot;https://gw.alicdn.com/tfs/TB1BqystrZnBKNjSZFrXXaRLFXa-183-144.png?getAvatar=1_.webp&quot;);"></div></div><div view-name="DTextView" style="display: inline-block; overflow: hidden; font-size: 11px; height: auto; margin-top: 5px; text-align: center; color: rgb(102, 102, 102); width: 61px; text-overflow: ellipsis; white-space: nowrap; line-height: 14px;">领金币</div></div><div view-name="DLinearLayout" aria-label="拍卖" style="display: flex; overflow: hidden; width: 61px; height: 67px; margin-left: 230.5px; margin-top: 84px; -webkit-box-orient: vertical; flex-direction: column; top: 0px; left: 0px; position: absolute;"><div view-name="HGifView" style="display: flex; overflow: hidden; width: 61px; height: 48px;"><div style="width: 100%; height: 100%; background-repeat: no-repeat; background-position: center center; background-size: contain; background-image: url(&quot;https://gw.alicdn.com/tfs/TB1CMf4tlnTBKNjSZPfXXbf1XXa-183-144.png?getAvatar=1_.webp&quot;);"></div></div><div view-name="DTextView" style="display: inline-block; overflow: hidden; font-size: 11px; height: auto; margin-top: 5px; text-align: center; color: rgb(102, 102, 102); width: 61px; text-overflow: ellipsis; white-space: nowrap; line-height: 14px;">拍卖</div></div><div view-name="DLinearLayout" aria-label="分类" style="display: flex; overflow: hidden; width: 61px; height: 67px; margin-left: 304px; margin-top: 84px; -webkit-box-orient: vertical; flex-direction: column; top: 0px; left: 0px; position: absolute;"><div view-name="HGifView" style="display: flex; overflow: hidden; width: 61px; height: 48px;"><div style="width: 100%; height: 100%; background-repeat: no-repeat; background-position: center center; background-size: contain; background-image: url(&quot;https://gw.alicdn.com/tfs/TB18P98tyQnBKNjSZFmXXcApVXa-183-144.png?getAvatar=1_.webp&quot;);"></div></div><div view-name="DTextView" style="display: inline-block; overflow: hidden; font-size: 11px; height: auto; margin-top: 5px; text-align: center; color: rgb(102, 102, 102); width: 61px; text-overflow: ellipsis; white-space: nowrap; line-height: 14px;">分类</div></div></div></div>'
  6. // 2 对象数组
  7. html:[
  8. {
  9. // 1 div标签 name属性来指定
  10. name:"div",
  11. // 2 标签上有哪些属性
  12. attrs:{
  13. // 标签上的属性 class style
  14. class:"my_div",
  15. style:"color:red;"
  16. },
  17. // 3 子节点 children 要接收的数据类型和 nodes第二种渲染方式的数据类型一致
  18. children:[
  19. {
  20. name:"p",
  21. attrs:{},
  22. // 放文本
  23. children:[
  24. {
  25. type:"text",
  26. text:"hello"
  27. }
  28. ]
  29. }
  30. ]
  31. }
  32. ]
  33. }
  34. })
uploading.4e448015.gif转存失败 重新上传 取消 uploading.4e448015.gif转存失败 重新上传 取消 uploading.4e448015.gif转存失败 重新上传 取消

 

 

十.   button 按钮开发 wxml

  1. <!--
  2. button 标签
  3. 1 外观的属性
  4. 1 size 控制按钮的大小
  5. 1 default 默认大小
  6. 2 mini 小尺寸
  7. 2 type 用来控制按钮的颜色
  8. 1 default 灰色
  9. 2 primary 绿色
  10. 3 warn 红色
  11. 3 plain 按钮是否镂空,背景色透明
  12. 4 loading 文字前显示正在等待图标
  13. -->
  14. <button>默认按钮</button>
  15. <button size="mini"> mini 默认按钮</button>
  16. <button type="primary"> primary 按钮</button>
  17. <button type="warn"> warn 按钮</button>
  18. <button type="warn" plain> plain 按钮</button>
  19. <button type="primary" loading> loading 按钮</button>
  20. <!--
  21. button 开发能力
  22. open-type:
  23. 1 contact 直接打开 客服对话功能 需要在微信小程序的后台配置 只能够通过真机调试来打开
  24. 2 share 转发当前的小程序 到微信朋友中 不能把小程序 分享到 朋友圈
  25. 3 getPhoneNumber 获取当前用户的手机号码信息 结合一个事件来使用 不是企业的小程序账号 没有权限来获取用户的手机号码
  26. 1 绑定一个事件 bindgetphonenumber
  27. 2 在事件的回调函数中 通过参数来获取信息
  28. 3 获取到的信息 已经加密过了
  29. 需要用户自己待见小程序的后台服务器,在后台服务器中进行解析 手机号码,返回到小程序中 就可以看到信息了
  30. 4 getUserInfo 获取当前用户的个人信息
  31. 1 使用方法 类似 获取用户的手机号码
  32. 2 可以直接获取 不存在加密的字段
  33. 5 launchApp 在小程序当中 直接打开 app
  34. 1 需要现在 app中 通过app的某个链接 打开 小程序
  35. 2 在小程序 中 再通过 这个功能 重新打开 app
  36. 3 找到 京东的app 和 京东的小程序
  37. 6 openSetting 打开小程序内置的 授权页面
  38. 1 授权页面中 只会出现 用户曾经点击过的 权限
  39. 7 feedback 打开 小程序内置的 意见反馈页面
  40. 1 只能够通过真机调试来打开
  41. -->
  42. <button open-type="contact">contact</button>
  43. <button open-type="share">share</button>
  44. <button open-type="getPhoneNumber" bindgetphonenumber="getPhoneNumber">getPhoneNumber</button>
  45. <button open-type="getUserInfo" bindgetuserinfo="getUserInfo">getUserInfo</button>
  46. <button open-type="launchApp">launchApp</button>
  47. <button open-type="openSetting">openSetting</button>
  48. <button open-type="feedback">feedback</button>
uploading.4e448015.gif转存失败 重新上传 取消

js

  1. // pages/demo13/demo13.js
  2. Page({
  3. // 获取用户的手机号码信息
  4. getPhoneNumber(e){
  5. console.log(e);
  6. },
  7. // 获取用户个人信息
  8. getUserInfo(e){
  9. console.log(e);
  10. }
  11. })
uploading.4e448015.gif转存失败 重新上传 取消

十一. 小程序中的字体图标 icon wxml

  1. <!--
  2. 小程序中的字体图标
  3. 1 type 图标的类型
  4. success|success_no_circle|info|warn|waiting|cancel|download|search|clear
  5. 2 size 大小
  6. 3 color 图标的颜色
  7. -->
  8. <icon type="cancel" size="60" color="#0094ff"> </icon>
uploading.4e448015.gif转存失败 重新上传 取消

 

十二.  radio 单选框 wxml

  1. <!--
  2. radio 单选框
  3. 1 radio标签 必须要和 父元素 radio-group来使用
  4. 2 value 选中的单选框的值
  5. 3 需要给 radio-group 绑定 change事件
  6. 4 需要在页面中显示 选中的值
  7. -->
  8. <radio-group bindchange="handleChange">
  9. <radio color="red" value="male"></radio>
  10. <radio color="red" value="female" ></radio>
  11. </radio-group>
  12. <view>您选中的是:{{gender}}</view>
uploading.4e448015.gif转存失败 重新上传 取消

js

  1. // pages/demo15/demo15.js
  2. Page({
  3. data: {
  4. gender: ""
  5. },
  6. handleChange(e){
  7. // 1 获取单选框中的值
  8. let gender=e.detail.value;
  9. // 2 把值 赋值给 data中的数据
  10. this.setData({
  11. // gender:gender
  12. gender
  13. })
  14. }
  15. })
uploading.4e448015.gif转存失败 重新上传 取消

九.  复选框  wxml

  1. <view>
  2. <checkbox-group bindchange="handleItemChange">
  3. <checkbox value="{{item.value}}" wx:for="{{list}}" wx:key="id">
  4. {{item.name}}
  5. </checkbox>
  6. </checkbox-group>
  7. <view>
  8. 选中的水果:{{checkedList}}
  9. </view>
  10. </view>
uploading.4e448015.gif转存失败 重新上传 取消

js

  1. // pages/demo16/demo16.js
  2. Page({
  3. data: {
  4. list:[
  5. {
  6. id:0,
  7. name:"馃崕",
  8. value:"apple"
  9. },
  10. {
  11. id:1,
  12. name:"馃崌",
  13. value:"grape"
  14. },
  15. {
  16. id:2,
  17. name:"馃崒",
  18. value:"bananer"
  19. }
  20. ],
  21. checkedList:[]
  22. },
  23. // 澶嶉€夋鐨勯€変腑浜嬩欢
  24. handleItemChange(e){
  25. // 1 鑾峰彇琚€変腑鐨勫閫夋鐨勫€? const checkedList=e.detail.value;
  26. // 2 杩涜璧嬪€? this.setData({
  27. checkedList
  28. })
  29. }
  30. })
uploading.4e448015.gif转存失败 重新上传 取消

十三. 自定义组件及传递数据  demo17.wxml

1.同级目录下右键点击新建目录 创建components->及Tabs目录

mini-01\components\Tabs

 

2. 在Tabs目录下 右键点击component 新建 component

3.新建完成 

4. Tabs.js

  1. // components/Tabs.js
  2. Component({
  3. /**
  4. * 里面存放的是 要从父组件中接收的数据
  5. */
  6. properties: {
  7. // 要接收的数据的名称
  8. // aaa:{
  9. // // type 要接收的数据的类型
  10. // type:String,
  11. // // value 默认值
  12. // value:""
  13. // }
  14. tabs:{
  15. type:Array,
  16. value:[]
  17. }
  18. },
  19. /**
  20. * 组件的初始数据
  21. */
  22. data: {
  23. // tabs
  24. },
  25. /*
  26. 1 页面.js 文件中 存放事件回调函数的时候 存放在data同层级下!!!
  27. 2 组件.js 文件中 存放事件回调函数的时候 必须要存在在 methods中!!!
  28. */
  29. methods: {
  30. hanldeItemTap(e){
  31. /*
  32. 1 绑定点击事件 需要在methods中绑定
  33. 2 获取被点击的索引
  34. 3 获取原数组
  35. 4 对数组循环
  36. 1 给每一个循环性 选中属性 改为 false
  37. 2 给 当前的索引的 项 添加激活选中效果就可以了!!!
  38. 5 点击事件触发的时候
  39. 触发父组件中的自定义事件 同时传递数据给 父组件
  40. this.triggerEvent("父组件自定义事件的名称",要传递的参数)
  41. */
  42. // 2 获取索引
  43. const {index}=e.currentTarget.dataset;
  44. // 5 触发父组件中的自定义事件 同时传递数据给
  45. this.triggerEvent("itemChange",{index});
  46. // 3 获取data中的数组
  47. // 解构 对 复杂类型进行结构的时候 复制了一份 变量的引用而已
  48. // 最严谨的做法 重新拷贝一份 数组,再对这个数组的备份进行处理,
  49. // let tabs=JSON.parse(JSON.stringify(this.data.tabs));
  50. // 不要直接修改 this.data.数据
  51. // let {tabs}=this.data;
  52. // let tabs=this.data;
  53. // 4 循环数组
  54. // [].forEach 遍历数组 遍历数组的时候 修改了 v ,也会导致源数组被修改
  55. // tabs.forEach((v,i)=>i===index?v.isActive=true:v.isActive=false);
  56. // this.setData({
  57. // tabs
  58. // })
  59. }
  60. }
  61. })

 

5.Tabs.json

  1. {
  2. "component": true,
  3. "usingComponents": {}
  4. }

 

6.Tabs.wxml

  1. <view class="tabs">
  2. <view class="tabs_title">
  3. <!-- <view class="title_item active">首页</view>
  4. <view class="title_item">原创</view>
  5. <view class="title_item">分类</view>
  6. <view class="title_item">关于</view> -->
  7. <view
  8. wx:for="{{tabs}}"
  9. wx:key="id"
  10. class="title_item {{item.isActive?'active':''}}"
  11. bindtap="hanldeItemTap"
  12. data-index="{{index}}"
  13. >
  14. {{item.name}}
  15. </view>
  16. </view>
  17. <view class="tabs_content">
  18. <!--
  19. slot 标签 其实就是一个占位符 插槽
  20. 等到 父组件调用 子组件的时候 再传递 标签过来 最终 这些被传递的标签
  21. 就会替换 slot 插槽的位置
  22. -->
  23. <slot></slot>
  24. </view>
  25. </view>

 

7.Tabs.wxss

  1. .tabs{}
  2. .tabs_title{
  3. display: flex;
  4. padding: 10rpx 0;
  5. }
  6. .title_item{
  7. flex: 1;
  8. display: flex;
  9. justify-content: center;
  10. align-items: center;
  11. }
  12. .active{
  13. color:red;
  14. border-bottom: 5rpx solid currentColor;
  15. }
  16. .tabs_content{}

 

8. 在需要使用的页面目录中 demo17.json 引入组件

  1. {
  2. "usingComponents": {
  3. "Tabs":"../../components/Tabs/Tabs"
  4. }
  5. }

 

9. demo17.wxml 引用自定义的组件 <Tabs> <T/abs>

  1. <!--
  2. 1 父组件(页面) 向子组件 传递数据 通过 标签属性的方式来传递
  3. 1 在子组件上进行接收
  4. 2 把这个数据当成是data中的数据直接用即可
  5. 2 子向父传递数据 通过事件的方式传递
  6. 1 在子组件的标签上加入一个 自定义事件
  7. -->
  8. <Tabs tabs="{{tabs}}" binditemChange="handleItemChange" >
  9. <block wx:if="{{tabs[0].isActive}}">0 </block>
  10. <block wx:elif="{{tabs[1].isActive}}">1 </block>
  11. <block wx:elif="{{tabs[2].isActive}}">2 </block>
  12. <block wx:else>3</block>
  13. </Tabs>
uploading.4e448015.gif转存失败 重新上传 取消

demo17.js

  1. // pages/demo17/demo18.js
  2. Page({
  3. /**
  4. * 页面的初始数据
  5. */
  6. data: {
  7. tabs: [
  8. {
  9. id: 0,
  10. name: "首页",
  11. isActive: true
  12. },
  13. {
  14. id: 1,
  15. name: "原创",
  16. isActive: false
  17. }
  18. ,
  19. {
  20. id: 2,
  21. name: "分类",
  22. isActive: false
  23. }
  24. ,
  25. {
  26. id: 3,
  27. name: "关于",
  28. isActive: false
  29. }
  30. ]
  31. },
  32. // 自定义事件 用来接收子组件传递的数据的
  33. handleItemChange(e) {
  34. // 接收传递过来的参数
  35. const { index } = e.detail;
  36. let { tabs } = this.data;
  37. tabs.forEach((v, i) => i === index ? v.isActive = true : v.isActive = false);
  38. this.setData({
  39. tabs
  40. })
  41. }
  42. })
uploading.4e448015.gif转存失败 重新上传 取消

 父组件向子组件传递数据:

子组件通过触发父组件事件来传递数据;

 

十四.  生命周期 wxml

  1. <!--pages/demo18/demo18.wxml-->
  2. <text>pages/demo18/demo18.wxml</text>
  3. <navigator url="/pages/demo17/demo17" open-type="navigate">
  4. demo17
  5. </navigator>
  6. <navigator url="/pages/demo17/demo17" open-type="redirect">
  7. demo17 redirect
  8. </navigator>
  9. <view>1</view>
  10. <view>2</view>
  11. <view>3</view>
  12. <view>4</view>
  13. <view>5</view>
  14. <view>6</view>
  15. <view>7</view>
  16. <view>8</view>
  17. <view>9</view>
  18. <view>10</view>
  19. <view>11</view>
  20. <view>12</view>
  21. <view>13</view>
  22. <view>14</view>
  23. <view>15</view>
  24. <view>16</view>
  25. <view>17</view>
  26. <view>18</view>
  27. <view>19</view>
  28. <view>20</view>
  29. <view>21</view>
  30. <view>22</view>
  31. <view>23</view>
  32. <view>24</view>
  33. <view>25</view>
  34. <view>26</view>
  35. <view>27</view>
  36. <view>28</view>
  37. <view>29</view>
  38. <view>30</view>
  39. <view>31</view>
  40. <view>32</view>
  41. <view>33</view>
  42. <view>34</view>
  43. <view>35</view>
  44. <view>36</view>
  45. <view>37</view>
  46. <view>38</view>
  47. <view>39</view>
  48. <view>40</view>
  49. <view>41</view>
  50. <view>42</view>
  51. <view>43</view>
  52. <view>44</view>
  53. <view>45</view>
  54. <view>46</view>
  55. <view>47</view>
  56. <view>48</view>
  57. <view>49</view>
  58. <view>50</view>
  59. <view>51</view>
  60. <view>52</view>
  61. <view>53</view>
  62. <view>54</view>
  63. <view>55</view>
  64. <view>56</view>
  65. <view>57</view>
  66. <view>58</view>
  67. <view>59</view>
  68. <view>60</view>
  69. <view>61</view>
  70. <view>62</view>
  71. <view>63</view>
  72. <view>64</view>
  73. <view>65</view>
  74. <view>66</view>
  75. <view>67</view>
  76. <view>68</view>
  77. <view>69</view>
  78. <view>70</view>
  79. <view>71</view>
  80. <view>72</view>
  81. <view>73</view>
  82. <view>74</view>
  83. <view>75</view>
  84. <view>76</view>
  85. <view>77</view>
  86. <view>78</view>
  87. <view>79</view>
  88. <view>80</view>
  89. <view>81</view>
  90. <view>82</view>
  91. <view>83</view>
  92. <view>84</view>
  93. <view>85</view>
  94. <view>86</view>
  95. <view>87</view>
  96. <view>88</view>
  97. <view>89</view>
  98. <view>90</view>
  99. <view>91</view>
  100. <view>92</view>
  101. <view>93</view>
  102. <view>94</view>
  103. <view>95</view>
  104. <view>96</view>
  105. <view>97</view>
  106. <view>98</view>
  107. <view>99</view>
  108. <view>100</view>

 

uploading.4e448015.gif转存失败 重新上传 取消 uploading.4e448015.gif转存失败 重新上传 取消 uploading.4e448015.gif转存失败 重新上传 取消 uploading.4e448015.gif转存失败 重新上传 取消 uploading.4e448015.gif转存失败 重新上传 取消 uploading.4e448015.gif转存失败 重新上传 取消 uploading.4e448015.gif转存失败 重新上传 取消 uploading.4e448015.gif转存失败 重新上传 取消 uploading.4e448015.gif转存失败 重新上传 取消 uploading.4e448015.gif转存失败 重新上传 取消 uploading.4e448015.gif转存失败 重新上传 取消 uploading.4e448015.gif转存失败 重新上传 取消 uploading.4e448015.gif转存失败 重新上传 取消 uploading.4e448015.gif转存失败 重新上传 取消 uploading.4e448015.gif转存失败 重新上传 取消

 

 

js

  1. // pages/demo18/demo18.js
  2. Page({
  3. /**
  4. * 页面的初始数据
  5. */
  6. data: {
  7. },
  8. /**
  9. * 生命周期函数--监听页面加载
  10. */
  11. onLoad: function (options) {
  12. console.log("onLoad");
  13. // onLoad发送异步请求来初始化页面数据
  14. },
  15. /**
  16. * 生命周期函数--监听页面显示
  17. */
  18. onShow: function () {
  19. console.log("onShow");
  20. },
  21. /**
  22. * 生命周期函数--监听页面初次渲染完成
  23. */
  24. onReady: function () {
  25. console.log("onReady");
  26. },
  27. /**
  28. * 生命周期函数--监听页面隐藏
  29. */
  30. onHide: function () {
  31. console.log("onHide");
  32. },
  33. /**
  34. * 生命周期函数--监听页面卸载 也是可以通过点击超链接来演示
  35. *
  36. */
  37. onUnload: function () {
  38. console.log("onUnload");
  39. },
  40. /**
  41. * 页面相关事件处理函数--监听用户下拉动作
  42. */
  43. onPullDownRefresh: function () {
  44. console.log("onPullDownRefresh");
  45. // 页面的数据 或者效果 重新 刷新
  46. },
  47. /**
  48. * 页面上拉触底事件的处理函数
  49. * 需要让页面 出现上下滚动才行
  50. */
  51. onReachBottom: function () {
  52. console.log("onReachBottom");
  53. // 上拉加载下一页数据
  54. },
  55. /**
  56. * 用户点击右上角分享
  57. */
  58. onShareAppMessage: function () {
  59. console.log("onShareAppMessage");
  60. },
  61. /**
  62. * 页面滚动 就可以触发
  63. */
  64. onPageScroll(){
  65. console.log("onPageScroll");
  66. },
  67. /**
  68. * 页面的尺寸发生改变的时候 触发
  69. * 小程序 发生了 横屏竖屏 切换的时候触发
  70. */
  71. onResize(){
  72. console.log("onResize");
  73. },
  74. /**
  75. * 1 必须要求当前页面 也是tabbar页面
  76. * 2 点击的自己的tab item的时候才触发
  77. */
  78. onTabItemTap(){
  79. console.log("onTabItemTap");
  80. }
  81. })
uploading.4e448015.gif转存失败 重新上传 取消 uploading.4e448015.gif转存失败 重新上传 取消 uploading.4e448015.gif转存失败 重新上传 取消 uploading.4e448015.gif转存失败 重新上传 取消 uploading.4e448015.gif转存失败 重新上传 取消 uploading.4e448015.gif转存失败 重新上传 取消 uploading.4e448015.gif转存失败 重新上传 取消 uploading.4e448015.gif转存失败 重新上传 取消 uploading.4e448015.gif转存失败 重新上传 取消 uploading.4e448015.gif转存失败 重新上传 取消 uploading.4e448015.gif转存失败 重新上传 取消 uploading.4e448015.gif转存失败 重新上传 取消 uploading.4e448015.gif转存失败 重新上传 取消 uploading.4e448015.gif转存失败 重新上传 取消 uploading.4e448015.gif转存失败 重新上传 取消

.json  开启横屏竖屏开发

  1. {
  2. "pageOrientation": "auto"
  3. }
uploading.4e448015.gif转存失败 重新上传 取消 uploading.4e448015.gif转存失败 重新上传 取消 uploading.4e448015.gif转存失败 重新上传 取消 uploading.4e448015.gif转存失败 重新上传 取消 uploading.4e448015.gif转存失败 重新上传 取消 uploading.4e448015.gif转存失败 重新上传 取消 uploading.4e448015.gif转存失败 重新上传 取消 uploading.4e448015.gif转存失败 重新上传 取消 uploading.4e448015.gif转存失败 重新上传 取消 uploading.4e448015.gif转存失败 重新上传 取消 uploading.4e448015.gif转存失败 重新上传 取消 uploading.4e448015.gif转存失败 重新上传 取消 uploading.4e448015.gif转存失败 重新上传 取消 uploading.4e448015.gif转存失败 重新上传 取消 uploading.4e448015.gif转存失败 重新上传 取消 uploading.4e448015.gif转存失败 重新上传 取消

全局文件

App.js

  1. //app.js
  2. App({
  3. // 1 应用第一次启动的就会触发的事件
  4. onLaunch() {
  5. // 在应用第一次启动的时候 获取用户的个人信息
  6. // console.log("onLaunch");
  7. // aabbcc
  8. // js的方式来跳转 不能触发 onPageNotFound
  9. // wx.navigateTo({
  10. // url: '/11/22/33'
  11. // });
  12. },
  13. // 2 应用 被用户看到
  14. onShow(){
  15. // 对应用的数据或者页面效果 重置
  16. // console.log("onShow");
  17. },
  18. // 3 应用 被隐藏了
  19. onHide(){
  20. // 暂停或者清除定时器
  21. // console.log("Hide");
  22. },
  23. // 4 应用的代码发生了报错的时候 就会触发
  24. onError(err){
  25. // 在应用发生代码报错的时候,收集用户的错误信息,通过异步请求 将错误的信息发送后台去
  26. // console.log("onError");
  27. // console.log(err);
  28. },
  29. // 5 页面找不到就会触发
  30. // 应用第一次启动的时候,如果找不到第一个入口页面 才会触发
  31. onPageNotFound(){
  32. // 如果页面不存在了 通过js的方式来重新跳转页面 重新跳到第二个首页
  33. // 不能跳到tabbar页面 导航组件类似
  34. wx.navigateTo({
  35. url: '/pages/demo09/demo09'
  36. });
  37. // console.log("onPageNotFound");
  38. }
  39. })

app.json

  1. {
  2. "pages": [
  3. "pages/demo18/demo18",
  4. "pages/demo17/demo17",
  5. "pages/demo16/demo16",
  6. "pages/demo15/demo15",
  7. "pages/demo14/demo14",
  8. "pages/demo13/demo13",
  9. "pages/demo12/demo12",
  10. "pages/demo11/demo11",
  11. "pages/demo10/demo10",
  12. "pages/demo09/demo09",
  13. "pages/demo08/demo08",
  14. "pages/demo07/demo07",
  15. "pages/demo06/demo06",
  16. "pages/demo05/demo05",
  17. "pages/demo04/demo04",
  18. "pages/demo03/demo03",
  19. "pages/demo01/demo01",
  20. "pages/index/index",
  21. "pages/img/img",
  22. "pages/mine/mine",
  23. "pages/search/search",
  24. "pages/demo02/demo02",
  25. "pages/logs/logs"
  26. ],
  27. "window": {
  28. "backgroundTextStyle": "dark",
  29. "navigationBarBackgroundColor": "#0094ff",
  30. "navigationBarTitleText": "我的应用",
  31. "navigationBarTextStyle": "black",
  32. "enablePullDownRefresh": true,
  33. "backgroundColor": "yellow"
  34. },
  35. "tabBar": {
  36. "list": [
  37. {
  38. "pagePath": "pages/index/index",
  39. "text": "首页",
  40. "iconPath": "icon/_home.png",
  41. "selectedIconPath": "icon/home.png"
  42. },
  43. {
  44. "pagePath": "pages/img/img",
  45. "text": "图片",
  46. "iconPath": "icon/_img.png",
  47. "selectedIconPath": "icon/img.png"
  48. },
  49. {
  50. "pagePath": "pages/mine/mine",
  51. "text": "我的",
  52. "iconPath": "icon/_my.png",
  53. "selectedIconPath": "icon/my.png"
  54. },
  55. {
  56. "pagePath": "pages/search/search",
  57. "text": "搜索",
  58. "iconPath": "icon/_search.png",
  59. "selectedIconPath": "icon/search.png"
  60. },
  61. {
  62. "pagePath": "pages/demo18/demo18",
  63. "text": "demo18",
  64. "iconPath": "icon/_search.png",
  65. "selectedIconPath": "icon/search.png"
  66. }
  67. ],
  68. "color":"#0094ff",
  69. "selectedColor":"#ff9400",
  70. "backgroundColor":"#ff5533",
  71. "position":"top"
  72. },
  73. "sitemapLocation": "sitemap.json"
  74. }

 

app.wxss

  1. /**app.wxss**/
  2. .container {
  3. height: 100%;
  4. display: flex;
  5. flex-direction: column;
  6. align-items: center;
  7. justify-content: space-between;
  8. padding: 200rpx 0;
  9. box-sizing: border-box;
  10. }

 

project.config.json

  1. {
  2. "description": "项目配置文件",
  3. "packOptions": {
  4. "ignore": []
  5. },
  6. "setting": {
  7. "urlCheck": true,
  8. "es6": false,
  9. "postcss": true,
  10. "minified": true,
  11. "newFeature": true,
  12. "autoAudits": false,
  13. "checkInvalidKey": true
  14. },
  15. "compileType": "miniprogram",
  16. "libVersion": "2.7.7",
  17. "appid": "wxad258ddc70c8662c",
  18. "projectname": "mini-01",
  19. "debugOptions": {
  20. "hidedInDevtools": []
  21. },
  22. "isGameTourist": false,
  23. "simulatorType": "wechat",
  24. "simulatorPluginLibVersion": {},
  25. "condition": {
  26. "search": {
  27. "current": -1,
  28. "list": []
  29. },
  30. "conversation": {
  31. "current": -1,
  32. "list": []
  33. },
  34. "plugin": {
  35. "current": -1,
  36. "list": []
  37. },
  38. "game": {
  39. "currentL": -1,
  40. "list": []
  41. },
  42. "miniprogram": {
  43. "current": 0,
  44. "list": [
  45. {
  46. "id": -1,
  47. "name": "不存在的页面",
  48. "pathName": "pages/de333mo17/de3333mo17",
  49. "query": "",
  50. "scene": null
  51. }
  52. ]
  53. }
  54. }
  55. }

sitemap.json

  1. {
  2. "desc": "关于本文件的更多信息,请参考文档 https://developers.weixin.qq.com/miniprogram/dev/framework/sitemap.html",
  3. "rules": [{
  4. "action": "allow",
  5. "page": "*"
  6. }]
  7. }

 

.json  开启横屏竖屏开发

 "pageOrientation": "auto"

 

 

 

声明:本文内容由网友自发贡献,转载请注明出处:【wpsshop博客】
推荐阅读
相关标签
  

闽ICP备14008679号