开始

image.png
和小纸条的这个页面是类似的
image.png

单独封装成一个组件。创建组件user-space-popup
image.png
image.png

paper-left-popup单独封装成一个组件。把paper-left-popup这个组件的所有内容都复制过来。
image.png
把css单独拿出来。当做公共的

image.png

  1. import userSpacePopup from '@/components/user-space/user-space-popup.vue';

image.png

  1. <!-- 操作菜单 -->
  2. <user-space-popup :show="show"></user-space-popup>

默认显示这个数据
image.png

  1. show:true,

image.png
这里改成个100
image.png

image.png

image.png
事件名修改
image.png

image.png

父组件监听子组件的方法

image.png

  1. <!-- 操作菜单 -->
  2. <user-space-popup :show="show"
  3. @hide="hidepopup"
  4. @lahei="lahei"
  5. @beizhu="beizhu"></user-space-popup>

取反。
image.png

  1. togleShow(){
  2. this.show=!this.show;
  3. },

image.png

  1. <!-- 操作菜单 -->
  2. <user-space-popup :show="show"
  3. @hide="togleShow"
  4. @lahei="lahei"
  5. @beizhu="beizhu"></user-space-popup>

image.png

  1. togleShow(){
  2. this.show=!this.show;
  3. },
  4. // 拉黑
  5. lahei(){
  6. console.log('拉黑');
  7. },
  8. // 备注
  9. beizhu(){
  10. console.log('备注');
  11. },

监听按钮事件

image.png

  1. onNavigationBarButtonTap(e) {
  2. if(e.index==0){
  3. this.togleShow();
  4. }
  5. },

image.png
操作之后隐藏按钮
image.png

默认不显示
image.png

本节代码

user-space-popup.vue组件

  1. <template>
  2. <view>
  3. <!-- 操作菜单 -->
  4. <view class="papar-left-popup-mask" v-show="show" @tap="hidepopup"></view>
  5. <view class="papar-left-popup" v-show="show">
  6. <view class="u-f-ac" hover-class="papar-left-popup-h" @tap="lahei">
  7. <view class="icon iconfont icon-sousuo"></view>
  8. 拉黑
  9. </view>
  10. <view class="u-f-ac" hover-class="papar-left-popup-h" @tap="beizhu">
  11. <view class="icon iconfont icon-qingchu"></view>
  12. 备注
  13. </view>
  14. </view>
  15. </view>
  16. </template>
  17. <script>
  18. export default {
  19. props:{
  20. show:Boolean
  21. },
  22. methods:{
  23. hidepopup(){
  24. this.$emit('hide');
  25. },
  26. lahei(){
  27. this.$emit('lahei');
  28. },
  29. beizhu(){
  30. this.$emit('beizhu');
  31. }
  32. }
  33. }
  34. </script>
  35. <style>
  36. .papar-left-popup-mask{
  37. position: fixed;
  38. right: 0;
  39. left: 0;
  40. top: 0upx;
  41. bottom: 0;
  42. z-index: 1999;
  43. }
  44. .papar-left-popup{
  45. position: fixed;
  46. right: 0;
  47. top: 100upx;
  48. background: #FFFFFF;
  49. z-index: 2000;
  50. width: 55%;
  51. box-shadow: 1upx 1upx 20upx 2upx #CCCCCC;
  52. }
  53. .papar-left-popup>view{
  54. padding: 20upx;
  55. font-size: 35upx;
  56. }
  57. .papar-left-popup>view>view{
  58. margin-right: 10upx;
  59. font-weight: bold;
  60. }
  61. .papar-left-popup-h{
  62. background: #EEEEEE;
  63. }
  64. </style>

user-space.vue页面

  1. <template>
  2. <view>
  3. <!-- 背景图 + 用户基本信息 -->
  4. <user-space-head :userinfo="userinfo"></user-space-head>
  5. <!-- 统计 -->
  6. <view class="user-space-data">
  7. <home-data :homedata="spacedata"></home-data>
  8. </view>
  9. <view class="height:20upx;background:F4F4F4;"></view>
  10. <!-- tabbar切换 -->
  11. <swiper-tab-head :tabBars="tabBars" :tabIndex="tabIndex" @tabtap="tabtap" scrollStyle="border-bottom:0;"
  12. scrollItemStyle="width:33%;">
  13. </swiper-tab-head>
  14. <block v-for="(item,index) in tablist" :key="index">
  15. <template v-if="tabIndex==0">
  16. <!-- 主页 -->
  17. <user-space-userinfo :userinfo="userinfo"></user-space-userinfo>
  18. </template>
  19. <template v-else-if="tabIndex==index">
  20. <block v-for="(list,listindex) in item.list" :key="listindex">
  21. <common-list :item="list" :index="listindex"></common-list>
  22. </block>
  23. <!-- 上拉加载 -->
  24. <load-more :loadtext="item.loadtext"></load-more>
  25. </template>
  26. </block>
  27. <!-- 操作菜单 -->
  28. <user-space-popup :show="show"
  29. @hide="togleShow"
  30. @lahei="lahei"
  31. @beizhu="beizhu"></user-space-popup>
  32. </view>
  33. </template>
  34. <script>
  35. import userSpaceHead from '@/components/user-space/user-space-head.vue';
  36. import swiperTabHead from '@/components/index/swiper-tab-head.vue';
  37. import homeData from '@/components/home/home-data.vue';
  38. import userSpaceUserinfo from '@/components/user-space/user-space-userinfo.vue';
  39. import commonList from '@/components/common/common-list.vue';
  40. import loadMore from '@/components/common/load-more.vue';
  41. import userSpacePopup from '@/components/user-space/user-space-popup.vue';
  42. export default {
  43. components: {
  44. userSpaceHead,
  45. homeData,
  46. swiperTabHead,
  47. userSpaceUserinfo,
  48. commonList,
  49. loadMore,
  50. userSpacePopup
  51. },
  52. data() {
  53. return {
  54. show:false,
  55. tabIndex: 0,
  56. tabBars: [{
  57. name: "主页",
  58. id: "zhuye"
  59. },
  60. {
  61. name: "糗事",
  62. id: "qiushi"
  63. }, {
  64. name: "动态",
  65. id: "dongtai"
  66. },
  67. ],
  68. userinfo: {
  69. bgimg: 1,
  70. userpic: '../../static/demo/userpic/11.jpg',
  71. username: '昵称',
  72. sex: 0,
  73. age: 20,
  74. isguanzhu: false,
  75. regtime: '2019-04-11',
  76. id: 1213,
  77. birthday: '1987-02-07',
  78. job: 'IT',
  79. path: '广东广州',
  80. qg: '已婚'
  81. },
  82. spacedata: [{
  83. name: "获赞",
  84. num: '10k'
  85. },
  86. {
  87. name: "关注",
  88. num: 0
  89. },
  90. {
  91. name: "粉丝",
  92. num: 0
  93. }
  94. ],
  95. tablist: [{
  96. loadtext: "上拉加载更多",
  97. list: [
  98. // 文字
  99. {
  100. userpic: "../../static/demo/userpic/12.jpg",
  101. username: "哈哈",
  102. sex: 0, //0 男 1 女
  103. age: 25,
  104. isguanzhu: false,
  105. title: "我是标题",
  106. titlepic: "",
  107. video: false,
  108. share: false,
  109. path: "深圳 龙岗",
  110. sharenum: 20,
  111. commentnum: 30,
  112. goodnum: 20
  113. },
  114. // 图文
  115. {
  116. userpic: "../../static/demo/userpic/12.jpg",
  117. username: "哈哈",
  118. sex: 0, //0 男 1 女
  119. age: 25,
  120. isguanzhu: false,
  121. title: "我是标题",
  122. titlepic: "../../static/demo/datapic/13.jpg",
  123. video: false,
  124. share: false,
  125. path: "深圳 龙岗",
  126. sharenum: 20,
  127. commentnum: 30,
  128. goodnum: 20
  129. },
  130. // 视频
  131. {
  132. userpic: "../../static/demo/userpic/12.jpg",
  133. username: "哈哈",
  134. sex: 0, //0 男 1 女
  135. age: 25,
  136. isguanzhu: false,
  137. title: "我是标题",
  138. titlepic: "../../static/demo/datapic/13.jpg",
  139. video: {
  140. looknum: "20w",
  141. long: "2:47"
  142. },
  143. share: false,
  144. path: "深圳 龙岗",
  145. sharenum: 20,
  146. commentnum: 30,
  147. goodnum: 20
  148. },
  149. ]
  150. },
  151. {
  152. loadtext: "上拉加载更多",
  153. list: [
  154. // 文字
  155. {
  156. userpic: "../../static/demo/userpic/12.jpg",
  157. username: "哈哈",
  158. sex: 0, //0 男 1 女
  159. age: 25,
  160. isguanzhu: false,
  161. title: "我是标题",
  162. titlepic: "",
  163. video: false,
  164. share: false,
  165. path: "深圳 龙岗",
  166. sharenum: 20,
  167. commentnum: 30,
  168. goodnum: 20
  169. },
  170. // 图文
  171. {
  172. userpic: "../../static/demo/userpic/12.jpg",
  173. username: "哈哈",
  174. sex: 0, //0 男 1 女
  175. age: 25,
  176. isguanzhu: false,
  177. title: "我是标题",
  178. titlepic: "../../static/demo/datapic/13.jpg",
  179. video: false,
  180. share: false,
  181. path: "深圳 龙岗",
  182. sharenum: 20,
  183. commentnum: 30,
  184. goodnum: 20
  185. },
  186. // 视频
  187. {
  188. userpic: "../../static/demo/userpic/12.jpg",
  189. username: "哈哈",
  190. sex: 0, //0 男 1 女
  191. age: 25,
  192. isguanzhu: false,
  193. title: "我是标题",
  194. titlepic: "../../static/demo/datapic/13.jpg",
  195. video: {
  196. looknum: "20w",
  197. long: "2:47"
  198. },
  199. share: false,
  200. path: "深圳 龙岗",
  201. sharenum: 20,
  202. commentnum: 30,
  203. goodnum: 20
  204. },
  205. ]
  206. },
  207. ]
  208. }
  209. },
  210. computed: {
  211. },
  212. // 上拉触底事件
  213. onReachBottom() {
  214. this.loadmore();
  215. },
  216. onNavigationBarButtonTap(e) {
  217. if(e.index==0){
  218. this.togleShow();
  219. }
  220. },
  221. methods: {
  222. togleShow(){
  223. this.show=!this.show;
  224. },
  225. // 拉黑
  226. lahei(){
  227. console.log('拉黑');
  228. this.togleShow();
  229. },
  230. // 备注
  231. beizhu(){
  232. console.log('备注');
  233. this.togleShow();
  234. },
  235. // tabbar点击事件
  236. tabtap(index) {
  237. // console.log(index);
  238. this.tabIndex = index;
  239. },
  240. loadmore() {
  241. if (this.tablist[this.tabIndex].loadtext != "上拉加载更多") {
  242. return;
  243. }
  244. // 修改状态
  245. this.tablist[this.tabIndex].loadtext = "加载中...";
  246. // 获取数据
  247. setTimeout(() => {
  248. //获取完成
  249. let obj = {
  250. userpic: "../../static/demo/userpic/12.jpg",
  251. username: "哈哈",
  252. sex: 0, //0 男 1 女
  253. age: 25,
  254. isguanzhu: false,
  255. title: "我是标题",
  256. titlepic: "../../static/demo/datapic/13.jpg",
  257. video: false,
  258. share: false,
  259. path: "深圳 龙岗",
  260. sharenum: 20,
  261. commentnum: 30,
  262. goodnum: 20
  263. };
  264. this.tablist[this.tabIndex].list.push(obj);
  265. this.tablist[this.tabIndex].loadtext = "上拉加载更多";
  266. }, 1000);
  267. }
  268. }
  269. }
  270. </script>
  271. <style>
  272. .user-spaace-margin {
  273. margin: 15upx 0;
  274. }
  275. </style>

结束