wepy - 與原生有什么不同(x.wpy)使用實例

?

?

源碼

  1 <template>
  2   <view class='mark' wx:if="{{showMark}}">
  3     <view animation="{{animationData}}" class="animCat">
  4       <image src="http://osk1hpe2y.bkt.clouddn.com/18-5-30/34559443.jpg"></image>
  5     </view>
  6     <button open-type="getUserInfo" lang="zh_CN" @getuserinfo="onGotUserInfo" class="css-button">開始吧!</button>
  7   </view>
  8   <!-- test-tab -->
  9   <view>
 10     <scroll-view scroll-x="true" class="tab-h" scroll-left="{{scrollLeft}}">
 11       <view class="tab-item {{currentTab==0?'active':''}}" data-current="0" bindtap="swichNav">快遞</view>
 12       <view class="tab-item {{currentTab==1?'active':''}}" data-current="1" bindtap="swichNav">身份證</view>
 13       <view class="tab-item {{currentTab==2?'active':''}}" data-current="2" bindtap="swichNav">銀行卡號</view>
 14       <view class="tab-item {{currentTab==3?'active':''}}" data-current="3" bindtap="swichNav">手機號碼</view>
 15       <view class="tab-item {{currentTab==4?'active':''}}" data-current="4" bindtap="swichNav">身材計算</view>
 16     </scroll-view>
 17     <swiper class="tab-content" current="{{currentTab}}" duration="300" bindchange="switchTab" style="height:{{winHeight}}rpx">
 18       <!-- 快遞查詢 -->
 19       <swiper-item wx:for="{{[0,1,2,3,4]}}" wx:key="*this">
 20         <scroll-view scroll-y="true" class="scoll-h" wx:if="{{index==0}}">
 21           <ForexpressItem :history.sync='history'></ForexpressItem>
 22         </scroll-view>
 23         <scroll-view scroll-y="true" class="scoll-h" wx:elif="{{index==1}}">
 24           <PeoPleCard></PeoPleCard>
 25         </scroll-view>
 26         <scroll-view scroll-y="true" class="scoll-h" wx:elif="{{index==2}}">
 27           <IdCard></IdCard>
 28         </scroll-view>
 29         <scroll-view scroll-y="true" class="scoll-h" wx:elif="{{index==3}}">
 30           <MobileHome></MobileHome>
 31         </scroll-view>
 32         <scroll-view scroll-y="true" class="scoll-h" wx:elif="{{index==4}}">
 33           <Figure></Figure>
 34         </scroll-view>
 35       </swiper-item>
 36     </swiper>
 37   </view>
 38 </template>
 39 
 40 <script>
 41   import wepy from 'wepy';
 42   import ForexpressItem from '@/components/express/index';
 43   import IdCard from '@/components/querys/idCard';
 44   import Figure from '@/components/querys/figure';
 45   import MobileHome from '@/components/querys/mobileHome';
 46   import PeoPleCard from '@/components/querys/peoPleCard';
 47   import {
 48     formatTime
 49   } from '@/utils/util';
 50   export default class Forexpress extends wepy.page {
 51     config = {
 52       navigationBarTitleText: '快遞查詢'
 53     };
 54     components = {
 55       ForexpressItem,
 56       IdCard,
 57       Figure,
 58       MobileHome,
 59       PeoPleCard
 60     };
 61     data = {
 62       showMark: false,
 63       winHeight: '', //窗口高度
 64       currentTab: 0, //預設當前項的值
 65       scrollLeft: 0, //tab標題的滾動條位置,
 66       searchArr: ['快遞', '身份證', '銀行卡號', '手機號碼', '身材'],
 67       history: []
 68     };
 69     methods = {
 70       switchTab: function(e) {
 71         let title = `${this.searchArr[e.detail.current]}查詢`;
 72         wx.setNavigationBarTitle({
 73           title: title
 74         });
 75         this.currentTab = e.detail.current;
 76         this.$apply();
 77         this.methods.checkCor.call(this);
 78       },
 79       // 點擊標題切換當前頁時改變樣式
 80       swichNav: function(e) {
 81         let title = `${this.searchArr[e.detail.current]}查詢`;
 82         wx.setNavigationBarTitle({
 83           title: title
 84         });
 85         var cur = e.target.dataset.current;
 86         if (this.data.currentTaB == cur) {
 87           return false;
 88         } else {
 89           this.currentTab = cur;
 90         }
 91       },
 92       //判斷當前滾動超過一屏時,設置tab標題滾動條。
 93       checkCor: function() {
 94         if (this.data.currentTab > 3) {
 95           this.scrollLeft = 300;
 96         } else {
 97           this.scrollLeft = 0;
 98         }
 99       },
100       onShareAppMessage() {
101         return {
102           title: '武侯的貓-打造最簡小工具',
103           path: 'pages/forexpress',
104           success(res) {
105             console.log(res);
106           },
107           fail(res) {
108             console.log(res);
109           }
110         };
111       },
112       onGotUserInfo(e) {
113         if (e.detail.userInfo) {
114           this.showMark = false;
115           wx.setStorage({
116             key: 'user',
117             data: e.detail.userInfo
118           });
119         }
120       }
121     };
122     onLoad() {
123       let that = this;
124       //動畫
125       var animation = wx.createAnimation({
126         duration: 1200,
127         timingFunction: 'linear'
128       });
129       this.animation = animation;
130       // animation.scale(2, 2).rotate(45).step()
131       this.setData({
132         animationData: animation.export()
133       });
134       try {
135         var res = wx.getSystemInfoSync();
136         //start
137         var clientHeight = res.windowHeight,
138           clientWidth = res.windowWidth,
139           rpxR = 750 / clientWidth;
140         var calc = (clientHeight - (1 / rpxR) * 80) * rpxR;
141         console.log(calc);
142         this.winHeight = calc;
143         //end
144       } catch (e) {
145         console.log('獲取設備信息失敗' + e);
146       }
147     }
148     onShow() {
149       let self = this;
150       try {
151         var res = wx.getStorageSync('user');
152         console.log(res);
153         if (res) this.showMark = false;
154         if (!res) this.showMark = true;
155         self.$apply();
156       } catch (e) {
157         this.showMark = true;
158       }
159       //快遞歷史
160       this.history = wx.getStorageSync('saveList');
161       this.$apply();
162     }
163   }
164 </script>
165 
166 <style lang="less" scoped>
167   .save {
168     position: fixed;
169     top: 20rpx;
170     left: 20rpx;
171     border: 2rpx solid #43cd80;
172     border-radius: 8rpx;
173     font-size: 26rpx;
174     text-align: center;
175     line-height: 30rpx;
176     padding: 8rpx;
177     background-color: #43cd80;
178     z-index: 9999;
179     color: #fff;
180     box-shadow: 2rpx 2rpx 1rpx 0 grey;
181   }
182   .animCat {
183     height: 50px;
184     width: 50px;
185     image {
186       height: 50px;
187       width: 50px;
188     }
189   }
190   .css-button {
191     width: 150px;
192     margin: 50% auto;
193     background: #138cff;
194     color: #fff;
195   }
196   .scan-code {
197     margin-right: 20rpx;
198     width: 80rpx;
199     height: 80rpx;
200     text-align: center;
201     line-height: 55rpx;
202     color: #138cff;
203     font-size: 24px;
204   }
205   .iconfont {
206     color: #4cc0e9;
207   }
208   page {
209     background-color: #fff; //background-image: linear-gradient(#7FC06E, #fff, #fff);
210   }
211   .express-img-wrap {
212     height: 200rpx; //   background-image: linear-gradient(#138cff, #fff);
213   }
214   .express-img {
215     width: 100%; //   height: 200rpx;
216     position: absolute;
217     top: 10%;
218     left: 50%;
219     transform: translateX(-50%);
220   }
221   .express-input-wrap {
222     position: relative;
223     display: flex;
224     align-items: center;
225     justify-content: center; //margin-top: 210rpx;
226     //background-image: linear-gradient(#7FC06E, #fff);
227     height: 100rpx; //border-bottom: 4rpx solid #7FC06E;
228     .express-input {
229       width: 60%;
230       height: 80rpx;
231       line-height: 80rpx;
232       font-size: 35rpx;
233       padding: 0 40rpx; //padding-left: rpx;
234       border: 3rpx solid #4cc0e9;
235       border-radius: 10rpx;
236       color: #666;
237     }
238   }
239   .express-input-wrap::before {
240     transform: translatex(40rpx); //line-height: 60rpx;
241     color: #999;
242   }
243   .express-input-wrap .icon-saoma {
244     height: 80rpx;
245     position: relative;
246     font-size: 80rpx;
247     line-height: 80rpx;
248     margin-left: 10rpx;
249   }
250   .del {
251     animation: dl 1s forwards; //margin: 0;
252   }
253   @keyframes dl {
254     0% {
255       transform: translate(0, 0);
256     }
257     10% {
258       transform: translate(-100rpx, 0);
259     }
260     100% {
261       transform: translate(1000rpx, -50rpx);
262       opacity: 0;
263     }
264   }
265   .history {
266     padding: 20rpx 10rpx;
267     box-sizing: border-box; //background-color: #f00;
268     //width: 100%;
269     height: auto;
270     margin: 0rpx 10rpx;
271     margin-bottom: 20rpx;
272     overflow: hidden;
273     position: relative;
274     display: flex;
275     align-items: center;
276     border: 1rpx solid #138cff;
277     border-radius: 20rpx;
278     box-shadow: 4rpx -2rpx 4rpx #ccc;
279     background: rgba(255, 255, 255, 0.8);
280     .info-wrap {
281       display: flex;
282       width: 180rpx;
283       flex-direction: column;
284       text-align: left;
285       margin-right: 8rpx;
286       .company {
287         font-size: 30rpx;
288       }
289       .number {
290         font-size: 24rpx;
291       }
292     }
293     .last-info-wrap {
294       font-size: 24rpx;
295       color: #666;
296     }
297     .phone {
298       font-size: 40rpx; //transform: translateY(-10rpx);
299     }
300     .delete {
301       width: 40rpx;
302       height: 40rpx;
303       position: absolute;
304       top: 5rpx;
305       right: 20rpx;
306       border: 1rpx solid #ccc;
307       border-radius: 10rpx;
308       padding: 5rpx 5rpx 5rpx 12rpx;
309       background: #63b8ff;
310       color: #cd5555;
311       font-size: 16px;
312     }
313   }
314   .time {
315     padding: 8rpx 0 0;
316   }
317   .mark {
318     width: 100%;
319     height: 100%;
320     position: fixed;
321     background: rgba(0, 0, 0, 0.8);
322     top: 0;
323     z-index: 100;
324     overflow: hidden;
325   }
326   // .container .icon-sousuo-copy {
327   //   color: #138cff;
328   // }
329   //test-tab start
330   .tab-h {
331     height: 80rpx;
332     width: 100%;
333     box-sizing: border-box;
334     overflow: hidden;
335     line-height: 80rpx;
336     background: #f7f7f7;
337     font-size: 16px;
338     white-space: nowrap;
339     position: fixed;
340     top: 0;
341     left: 0;
342     z-index: 99;
343   }
344   .tab-item {
345     margin: 0 36rpx;
346     display: inline-block;
347   }
348   .tab-item.active {
349     color: #4675f9;
350     position: relative;
351   }
352   .tab-item.active:after {
353     content: '';
354     display: block;
355     height: 8rpx;
356     width: 100%;
357     background: #4675f9;
358     position: absolute;
359     bottom: 0;
360     left: 5rpx;
361     border-radius: 16rpx;
362   }
363   .item-ans {
364     width: 100%;
365     display: flex;
366     flex-grow: row no-wrap;
367     justify-content: space-between;
368     padding: 30rpx;
369     box-sizing: border-box;
370     height: 180rpx;
371     align-items: center;
372     border-bottom: 1px solid #f2f2f2;
373   }
374   .avatar {
375     width: 100rpx;
376     height: 100rpx;
377     position: relative;
378     padding-right: 30rpx;
379   }
380   .avatar .img {
381     width: 100%;
382     height: 100%;
383   }
384   .avatar .doyen {
385     width: 40rpx;
386     height: 40rpx;
387     position: absolute;
388     bottom: -2px;
389     right: 20rpx;
390   }
391   .expertInfo {
392     font-size: 12px;
393     flex-grow: 2;
394     color: #b0b0b0;
395     line-height: 1.5em;
396   }
397   .expertInfo .name {
398     font-size: 16px;
399     color: #000;
400     margin-bottom: 6px;
401   }
402   .askBtn {
403     width: 120rpx;
404     height: 60rpx;
405     line-height: 60rpx;
406     text-align: center;
407     font-size: 14px;
408     border-radius: 60rpx;
409     border: 1px solid #4675f9;
410     color: #4675f9;
411   }
412   .tab-content {
413     margin-top: 80rpx;
414   }
415   .scoll-h {
416     height: 100%;
417   }
418 </style>
View Code

?

頁面模板

<style>
</style><template><view>監聽值:{{num}}</view>
</template><script>
import wepy from 'wepy';let _page,_this;export default class ep extends wepy.page {data = {num: 1};// 新的,引入了例如監聽watch,還有組件通訊等新概念...watch = {num(newValue, oldValue) {console.log(`num value: ${oldValue} -> ${newValue}`);}};onLoad() {console.log('頁面加載');}onShow(){console.log('頁面顯示!');}onHide(){console.log('頁面隱藏');}onUnload(){console.log('頁面卸載');}
}
</script>

?

?

引入了組件化導入(相比小程序原生來說,強大很多) -> 源碼在上,演示如下

?

?

?

?

轉載于:https://www.cnblogs.com/cisum/p/9880068.html

本文來自互聯網用戶投稿,該文觀點僅代表作者本人,不代表本站立場。本站僅提供信息存儲空間服務,不擁有所有權,不承擔相關法律責任。
如若轉載,請注明出處:http://www.pswp.cn/news/249109.shtml
繁體地址,請注明出處:http://hk.pswp.cn/news/249109.shtml
英文地址,請注明出處:http://en.pswp.cn/news/249109.shtml

如若內容造成侵權/違法違規/事實不符,請聯系多彩編程網進行投訴反饋email:809451989@qq.com,一經查實,立即刪除!

相關文章

vue從入門到精通之高級篇(一)vue-router的高級用法

今天要介紹的是路由元信息&#xff0c;滾動行為以及路由懶加載這幾個的使用方法。 1.路由元信息 什么是路由元信息&#xff0c;看看官網的解釋&#xff0c;定義路由的時候可以配置 meta 字段可以匹配meta字段&#xff0c;那么我們該如何使用它&#xff0c;一個簡單的例子&…

Java 數組實現堆棧操作

class Stack {private int stck[] ; private int tos ; Stack(int size) { // 一個參數的構造參數stck new int[size] ; // 創建數組&#xff08;創建堆棧&#xff09;tos -1 ; // 空堆棧標識 -1}// 堆棧操作的特性&#xff1a;先進后出、后進先出void push(int…

re模塊

什么是正則表達式 一組特殊符號組成的表達式&#xff0c;用于描述某種規則。該應用場景生活中隨處可見。 例如&#xff1a;讓有志青年過上體面的生活&#xff0c;這里面就由規則&#xff0c;即有志青年。 正則表達式的作用&#xff0c;以及使用場景 用于從字符串中匹配滿足某種…

CSS實現div梯形分割

原理 使用的border邊框屬性結合svg 轉換 詳見代碼 <!DOCTYPE html> <html lang"en"> <head><meta charset"UTF-8"><title>css實現div邊框斜角</title><style type"text/css"> .labels {display: i…

算法學習——決策單調性優化DP

update in 2019.1.21 優化了一下文中年代久遠的代碼 的格式…… 什么是決策單調性&#xff1f; 在滿足決策單調性的情況下&#xff0c;通常決策點會形如1111112222224444445555588888..... 即不可能會出現后面點的決策點小于前面點的決策點這種情況。 那么這個性質應該如何使用…

SVG畫一個箭頭

參考菜鳥手冊&#xff1a; https://www.runoob.com/svg/svg-tutorial.html 打開菜鳥中的在線工具 在可視化截圖拖拉元素繪制箭頭 點擊command U 查看源碼 將源碼拷入html代碼中&#xff0c;查看效果 最后&#xff0c;貼出源碼供大家參考 <!DOCTYPE html> <…

HP Instant Information

HP Instant Information before HP-UX 11i v3 《管理系統和工作組&#xff1a;HP-UX系統管理員指南》 After HP-UX 11i v3 《HP-UX系統管理指南》(由多個文檔組成的文檔集) 《HP-UX系統管理員指南&#xff1a;概述》 《HP-UX系統管理員指南&#xff1a;配置管理》 《HP-UX系統管…

CodeForces 258D Little Elephant and Broken Sorting(期望)

CF258D Little Elephant and Broken Sorting 題意 題意翻譯 有一個\(1\sim n\)的排列&#xff0c;會進行\(m\)次操作&#xff0c;操作為交換\(a,b\)。每次操作都有\(50\%\)的概率進行。 求進行\(m\)次操作以后的期望逆序對個數。 \(n,m\le 1000\) 輸入輸出格式 輸入格式&#x…

記一次vue項目yarn打包環境配置失效的解決方案

項目中使用到了yarn打包工程&#xff0c;主要有以下幾個命名。 # build for production with minification yarn run build# build for production and view the bundle analyzer report yarn run build --report# 自定義API地址 baseurl"http://127.0.0.1:8080/api/&quo…

數字簽名與HTTPS詳解

因為HTTP協議本身存在著明文傳輸、不能很好的驗證通信方的身份和無法驗證報文的完整性等一些安全方面的確點&#xff0c;所以才有了HTTPS的缺陷。HTTPS確切的的說不是一種協議&#xff0c;而是HTTP SSL (TSL)的結合體。HTTP報文經過SSL層加密后交付給TCP層進行傳輸。SSL(安全套…

[BZOJ4320][ShangHai2006]Homework(根號分治+并查集)

對于<sqrt(300000)的詢問&#xff0c;對每個模數直接記錄結果&#xff0c;每次加入新數時暴力更新每個模數的結果。 對于>sqrt(300000)的詢問&#xff0c;枚舉倍數&#xff0c;每次查詢大于等于這個倍數的最小數是多少&#xff0c;這個操作通過將詢問逆序使用并查集支持。…

VScode 結局插件prettier和vetur格式化沖突

先上配置代碼 {"workbench.iconTheme": "vscode-icons","workbench.startupEditor": "newUntitledFile","workbench.colorTheme": "One Dark Pro","editor.fontSize": 14,"editor.tabSize":…

WPF效果(GIS三維續篇)

去年這個時候簡單的摸索了一下三維的GIS相關的東西,也就是僅僅玩耍了一把,這次來點真正用的上的干貨效果效果&#xff1a; 1、加載自定義百度樣式的瓦片效果 2、加載自定義百度樣式的縮放效果 3、快速手動進去咱的大帝都 4、加載海量Mark效果 5、加載海量Mark和簡單模型效果 6、…

vue 表單 驗證 async-validator

1、使用插件async-validator async-validator 地址&#xff1a;https://github.com/yiminghe/async-validator 2、示例&#xff08;vueelement-ui&#xff09; <el-form :model"numberValidateForm" ref"numberValidateForm" label-width"100px&qu…

[19/04/23-星期二] GOF23_創建型模式(工廠模式、抽象工廠模式)

一、工廠模式(分為&#xff1a;簡單工廠模式、工廠方法模式、抽象工廠模式) 實現了創建者和調用者的分離 核心本質&#xff1a;1、實例化對象&#xff0c;用工廠方法代替new操作&#xff1b;2、將選擇實現類、創建對象統一管理和控制&#xff0c;從而將調用者跟實現類解耦。 簡…

Chrome瀏覽器12px問題-webkit-text-size-adjust: none 已失效的解決方案

對于早期的chrome, 如果要想顯示12px以下的字體&#xff0c;一般通用的方案都是在對應的元素中添加 div {-webkit-text-size-adjust: none; }但是我今天遇到的需求&#xff0c;添加了之后沒有反應&#xff0c;而且瀏覽就根本不支持這種寫法。 在網上看到了博客《Chrome瀏覽器…

CSRFGuard工具介紹

理解CSRFGuard的基礎&#xff1a;http://www.runoob.com/jsp/jsp-tutorial.html 1&#xff1a;您需要做的第一件事是將OWASP.CSRFARGAD.JAR庫復制到類路徑中。放置Owasp.CsrfGuard.jar最常見的類路徑位置在Web應用程序的WEB-INF文件夾的lib目錄中。 OWASP CSRFGARD 3在傳統Java…

[19/04/24-星期三] GOF23_創建型模式(建造者模式、原型模式)

一、建造者模式 本質&#xff1a;分離了對象子組件的單獨構造(由Builder負責)和裝配的分離(由Director負責)&#xff0c;從而可以構建出復雜的對象&#xff0c;這個模式適用于&#xff1a;某個對象的構建過程十分復雜 好處&#xff1a;由于構建和裝配的解耦&#xff0c;不同的構…

深入理解vue中的slot與slot-scope

寫在前面 vue中關于插槽的文檔說明很短&#xff0c;語言又寫的很凝練&#xff0c;再加上其和methods&#xff0c;data&#xff0c;computed等常用選項在使用頻率、使用先后上的差別&#xff0c;這就有可能造成初次接觸插槽的開發者容易產生“算了吧&#xff0c;回頭再學&#…

js 轉義

1. JavaScript 特殊字符 2. 正反斜杠互相替換 a/b/c.replace(/\//g,\\) // "a\b\c" $0.value.replace(/\\/g,\/) // a/b/c 獲取到 而不提取出 某個值后進行直接處理 \ 有轉義功能&#xff0c;所以一旦解析必然轉義&#xff0c;通常是直接獲取到數據源…