开始

一个view组件,里面嵌套两个view 分上下两个。
image.png

image.png

  1. <view class="paper-left-popup">
  2. <view><view class=""></view> 加糗友</view>
  3. <view><view class=""></view> 清除缓存</view>
  4. </view>

加上图标
image.png

image.png

  1. <view class="paper-left-popup">
  2. <view><view class="icon iconfont icon-sousuo"></view> 加糗友</view>
  3. <view><view class="icon iconfont icon-qingchu"></view> 清除缓存</view>
  4. </view>

fixed定位
image.png

image.png
阴影
image.png

  1. .paper-left-popup{
  2. position: fixed;
  3. right: 0;
  4. top: 10upx;
  5. background: #FFFFFF;
  6. z-index: 2000;
  7. width: 55%;
  8. box-shadow: 1upx 1upx 20upx 2upx #CCCCCC;
  9. }

image.png
flex布局。
image.png

  1. class="u-f-ac">

加点内边距
image.png
字体大小,左侧图标距离文字边距
image.png

  1. .paper-left-popup>view{
  2. padding: 20upx;
  3. font-size: 35upx;
  4. }
  5. .paper-left-popup>view>view{
  6. margin-left: 10upx;
  7. }

图标加粗
image.png

  1. .paper-left-popup>view>view{
  2. margin-left: 10upx;
  3. font-weight: bold;
  4. }

image.png

加上点击的效果,点击后边灰色。

image.png

  1. hover-class="paper-left-popup-h"

改背景色
image.png

  1. .paper-left-popup-h{
  2. background: #EEEEEE;
  3. }

鼠标滑过,还要点击一下。
image.png

点击事件+点击其他地方隐藏

show来控制显示和隐藏。
image.png

  1. show:true,

image.png

  1. v-show="show"

image.png

  1. @tap="addfriend"
  2. @tap="clear"

image.png

image.png

  1. addfriend() {
  2. console.log('加糗友');
  3. },
  4. clear() {
  5. console.log('清楚缓存');
  6. },
  7. hidepopup(){
  8. this.show=false;
  9. },
  10. showpopup(){
  11. this.show=true;
  12. }

image.png

  1. addfriend() {
  2. console.log('加糗友');
  3. this.hidepopup();
  4. },
  5. clear() {
  6. console.log('清楚缓存');
  7. this.hidepopup();
  8. },
  9. hidepopup(){
  10. this.show=false;
  11. },
  12. showpopup(){
  13. this.show=true;
  14. }

image.png
隐藏了
image.png
控制台的输出
image.png

点击其他地方关闭

加一个蒙版是透明的。
image.png

  1. <view class="paper-left-popup-mask"></view>

image.png

  1. <view class="paper-left-popup-mask" v-show="show" @tap="hidepopup"></view>

上下左右都为0 铺满窗口
image.png

  1. .paper-left-popup-mask{
  2. position: fixed;
  3. right: 0;
  4. left: 0;
  5. top: 0;
  6. bottom: 0;
  7. }

加个颜色。z-index在 弹窗的下面。
image.png

  1. .paper-left-popup-mask{
  2. position: fixed;
  3. right: 0;
  4. left: 0;
  5. top: 0;
  6. bottom: 0;
  7. background: #333333;
  8. z-index: 1999;
  9. }

点击黑色的区域会隐藏。
image.png
蒙版颜色去掉。让用户感觉,点击其他地方就会隐藏。
image.png

监听导航栏按钮事件

点击加好的时候弹窗层。

默认不显示。
image.png
输入onbutton。右侧的提示 选择第一个。
image.png

image.png

image.png

image.png

image.png

  1. onNavigationBarButtonTap(e) {
  2. switch(e.index){
  3. case 0:
  4. console.log('点击了左边按钮');
  5. break;
  6. case 1:
  7. this.showpopup();
  8. break;
  9. }
  10. },

image.png
点击左侧按钮不会隐藏右边
image.png

image.png

  1. onNavigationBarButtonTap(e) {
  2. switch(e.index){
  3. case 0:
  4. console.log('点击了左边按钮');
  5. this.hidepopup();
  6. break;
  7. case 1:
  8. this.showpopup();
  9. break;
  10. }
  11. },

本节代码

  1. <template>
  2. <view class="body">
  3. <view class="paper-left-popup-mask" v-show="show" @tap="hidepopup"></view>
  4. <view class="paper-left-popup" v-show="show">
  5. <view class="u-f-ac" hover-class="paper-left-popup-h" @tap="addfriend">
  6. <view class="icon iconfont icon-sousuo"></view> 加糗友
  7. </view>
  8. <view class="u-f-ac" hover-class="paper-left-popup-h" @tap="clear">
  9. <view class="icon iconfont icon-qingchu"></view> 清除缓存
  10. </view>
  11. </view>
  12. <!-- 小纸条列表 -->
  13. <block v-for="(item,index) in list" :key="index">
  14. <paper-list :item="item" :index="index"></paper-list>
  15. </block>
  16. <!-- 上拉加载 -->
  17. <load-more :loadtext="loadtext"></load-more>
  18. </view>
  19. </template>
  20. <script>
  21. import paperList from '@/components/paper/paper-list.vue';
  22. import loadMore from '@/components/common/load-more.vue';
  23. export default {
  24. components: {
  25. paperList,
  26. loadMore
  27. },
  28. data() {
  29. return {
  30. show:false,
  31. loadtext: "上拉加载更多",
  32. list: [{
  33. userpic: "../../static/demo/userpic/12.jpg",
  34. username: "昵称",
  35. time: "10:21",
  36. data: "我是信息",
  37. noreadnum: 2
  38. },
  39. {
  40. userpic: "../../static/demo/userpic/12.jpg",
  41. username: "昵称",
  42. time: "10:21",
  43. data: "我是信息",
  44. noreadnum: 0
  45. },
  46. {
  47. userpic: "../../static/demo/userpic/12.jpg",
  48. username: "昵称",
  49. time: "10:21",
  50. data: "我是信息",
  51. noreadnum: 0
  52. },
  53. {
  54. userpic: "../../static/demo/userpic/12.jpg",
  55. username: "昵称",
  56. time: "10:21",
  57. data: "我是信息",
  58. noreadnum: 11
  59. },
  60. {
  61. userpic: "../../static/demo/userpic/12.jpg",
  62. username: "昵称",
  63. time: "10:21",
  64. data: "我是信息",
  65. noreadnum: 2
  66. },
  67. {
  68. userpic: "../../static/demo/userpic/12.jpg",
  69. username: "昵称",
  70. time: "10:21",
  71. data: "我是信息",
  72. noreadnum: 0
  73. },
  74. {
  75. userpic: "../../static/demo/userpic/12.jpg",
  76. username: "昵称",
  77. time: "10:21",
  78. data: "我是信息",
  79. noreadnum: 0
  80. },
  81. {
  82. userpic: "../../static/demo/userpic/12.jpg",
  83. username: "昵称",
  84. time: "10:21",
  85. data: "我是信息",
  86. noreadnum: 11
  87. }
  88. ]
  89. }
  90. },
  91. // 监听下拉刷新
  92. onPullDownRefresh() {
  93. this.getdata()
  94. },
  95. onReachBottom() {
  96. this.loadmore();
  97. },
  98. onNavigationBarButtonTap(e) {
  99. switch(e.index){
  100. case 0:
  101. console.log('点击了左边按钮');
  102. this.hidepopup();
  103. break;
  104. case 1:
  105. this.showpopup();
  106. break;
  107. }
  108. },
  109. methods: {
  110. // 上拉加载
  111. loadmore() {
  112. if (this.loadtext != "上拉加载更多") {
  113. return;
  114. }
  115. // 修改状态
  116. this.loadtext = "加载中...";
  117. // 获取数据
  118. setTimeout(() => {
  119. //获取完成
  120. let obj = {
  121. userpic: "../../static/demo/userpic/12.jpg",
  122. username: "昵称",
  123. time: "10:21",
  124. data: "我是信息",
  125. noreadnum: 11
  126. };
  127. this.list.push(obj);
  128. this.loadtext = "上拉加载更多";
  129. }, 1000);
  130. //this.loadtext="没有更多数据了";
  131. },
  132. // 获取数据
  133. getdata() {
  134. setTimeout(() => {
  135. // 服务器获取数据
  136. let arr = [{
  137. userpic: "../../static/demo/userpic/12.jpg",
  138. username: "昵称1111",
  139. time: "10:21",
  140. data: "我是信息",
  141. noreadnum: 2
  142. },
  143. {
  144. userpic: "../../static/demo/userpic/12.jpg",
  145. username: "昵称222",
  146. time: "10:21",
  147. data: "我是信息",
  148. noreadnum: 0
  149. },
  150. {
  151. userpic: "../../static/demo/userpic/12.jpg",
  152. username: "昵称333",
  153. time: "10:21",
  154. data: "我是信息",
  155. noreadnum: 0
  156. },
  157. {
  158. userpic: "../../static/demo/userpic/12.jpg",
  159. username: "昵称444",
  160. time: "10:21",
  161. data: "我是信息",
  162. noreadnum: 11
  163. }
  164. ];
  165. // 赋值
  166. this.list = arr;
  167. // 关闭下拉刷新
  168. uni.stopPullDownRefresh();
  169. }, 2000);
  170. },
  171. addfriend() {
  172. console.log('加糗友');
  173. this.hidepopup();
  174. },
  175. clear() {
  176. console.log('清楚缓存');
  177. this.hidepopup();
  178. },
  179. hidepopup(){
  180. this.show=false;
  181. },
  182. showpopup(){
  183. this.show=true;
  184. }
  185. }
  186. }
  187. </script>
  188. <style>
  189. .body {
  190. padding: 0 20upx;
  191. }
  192. .paper-left-popup{
  193. position: fixed;
  194. right: 0;
  195. top: 10upx;
  196. background: #FFFFFF;
  197. z-index: 2000;
  198. width: 55%;
  199. box-shadow: 1upx 1upx 20upx 2upx #CCCCCC;
  200. }
  201. .paper-left-popup>view{
  202. padding: 20upx;
  203. font-size: 35upx;
  204. }
  205. .paper-left-popup>view>view{
  206. margin-left: 10upx;
  207. font-weight: bold;
  208. }
  209. .paper-left-popup-h{
  210. background: #EEEEEE;
  211. }
  212. .paper-left-popup-mask{
  213. position: fixed;
  214. right: 0;
  215. left: 0;
  216. top: 0;
  217. bottom: 0;
  218. /* background: #333333; */
  219. z-index: 1999;
  220. }
  221. </style>

结束