灏忕▼搴忔鏋禬ePY 浠庡叆闂ㄥ埌鏀惧純韪╁潙鍚堥泦
Posted 闃垮叺
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了灏忕▼搴忔鏋禬ePY 浠庡叆闂ㄥ埌鏀惧純韪╁潙鍚堥泦相关的知识,希望对你有一定的参考价值。
灏忕▼搴忔鏋禬ePY 浠庡叆闂ㄥ埌鏀惧純韪╁潙鍚堥泦
涓€鐐圭偣浠嬬粛WePY
鍥犱负灏忕▼搴忕殑璇硶璁捐鐣ヨ糠锛?br>鎵€浠?sup>x1 妯″潡鍖栬捣鏉ュ苟涓嶆柟渚匡紝
鎵€浠?sup>x2 鍚勫巶灏卞嚭浜嗕笉灏戠殑妗嗘灦鐢ㄤ互鏂逛究灏忕▼搴忕殑寮€鍙戯紝
鑵捐鐪嬪埌鍒汉瀹堕兘鍑轰簡妗嗘灦浜嗛偅鐪嬫潵鎴戠殑灏忕▼搴忓彲鑳界湡鐨勪笉澶柟渚垮紑鍙戝挴锛岄偅鎴戜篃鍑轰竴涓惂馃
鎵€浠?sup>x3 WePY 灏辫繖涔堟í绌哄嚭涓栦簡銆?/p>
閭e皬楣呴箙馃惂 浣犳棭骞插槢鍘讳簡鍟婏紝涓轰粈涔堜笉鎶婂皬绋嬪簭璁捐鐨勫ソ鐢ㄤ竴鐐圭偣锛佺▼搴忓憳濂藉ソ鐜╂槸鍚э紒
鍚屾牱鏄豢鍘熺敓搴旂敤浣犲氨涓嶈兘瀛﹀浜哄Electron 鎶婄晫闈氦缁欑綉椤靛師鐢烪TML 鍘诲鐞嗕箞锛屾悶涓€鍫嗚醇娌$敤缁勪欢鍚勭濂囧鎬€殑闂銆傘€?/p>
绋嬪簭鍛樹綍鑻︿负闅剧▼搴忕尶鍟婐煒?/p>
涓嶅ソ鎰忔€濇縺鍔ㄤ簡馃檮
涓婇潰馃憜 閮芥槸鎴戝惞鐨勫叾瀹濿ePY 鏄渶鏃╃殑灏忕▼搴忔鏋朵箣涓€馃槀
WePY 鏄竴涓紑鍙戦鏍肩被浼糣ue.js, 鏀寔绫讳技Props, Mixin, Computed, Slot 绛夌壒鎬х殑椋庢牸寮€鍙戯紝
鏀寔缁勪欢鍖?妯″潡鍖栵紝NPM 渚濊禆锛孭romise/Async, ESnext, Less/Sass/Styus, Babel/Typescript 鐨勪竴涓皬绋嬪簭寮€鍙戞鏋躲€?/p>
璇硶涓婄被浼糣ue.js 澶氫竴鐐癸紝浣滀负涓€涓猂eact 鍏氭垜骞舵病鏈夊緢鍠滄锛屼絾鍙兘Vue 鍏氫篃涓嶄竴瀹氬氨鍠滄銆?br>姣曠珶瀹冨彧鏄儚锛屽苟娌℃湁寰堜竴鏍凤紝寮€鍙戣捣鏉ヨ窡鍋氳繛杩炵湅浼肩殑璺烿ue.js 鍚勭琛屼负涓嶄竴鑷淬€傘€?/p>
闂茶瘽灏辫鍒拌繖浜嗭紝寮€濮嬭姝d簨銆?/p>
閭d簺瑕佹敞鎰忕殑鐐?/h2>
姝よ妭鍐呭鍙傝€?<u>灏忚壊灏忛瓟</u> 浜?<u>2018-03-20</u> 鍙戝竷鍦?Segmentfault 鐨勬枃绔?Wepy-灏忕▼搴忚俯鍧戣
ALL CREDIT GOES TO HIM THANKS ALOT
棣栧厛鏄枃妗g被锛?/p>
WePY棣栭〉
WePY瀹樻柟鏂囨。
灏忕▼搴忓畼鏂规枃妗?/a>
WePY Github Issues
鐒跺悗鏄竴浜涜鐐癸細
1. Data 鍙婃暟鎹粦瀹?/h3>
1.1 瀵逛簬鍙兘鐢ㄥ埌鐨勬墍鏈夋暟鎹棰勫厛缁欏€硷紝鍗宠鍏堝湪data 涓垵濮嬪寲锛涘惁鍒欎箣鍚庢洿鏂版暟鎹椂灏嗕笉浼氳Е鍙戣剰鏁版嵁妫€鏌ユ祦绋嬶紝涔熷氨涓嶄細瑙﹀彂椤甸潰閲嶆覆鏌撱€?/p>
1.2 鏇存柊鏁版嵁鏃跺彲浠ョ洿鎺ョ敤 this.foo = bar
, 涓嶇敤寰俊鍘熺敓鐨?this.setData
鏂规硶銆?/p>
class Fn extends wepy.page {
data = {
foo: 1,
// bar: 2, 姝ゅ涓嶅0鏄?bar
}
someFunction() {
// 椤甸潰鏇存柊
this.foo = 10;
// 杩欎笉鐢熸晥
this.bar = 20;
}
}
1.3 鏁版嵁鍦ㄦā鏉夸腑杩涜缁戝畾鏃跺彲浠ョ敤 :foo=bar
鐨勫舰寮忚繘琛岀粦瀹氥€傛敞鎰忛潪瀛楃绫诲瀷鐨勶紙姣斿璇村竷灏斿€硷級鍙婂彉閲忚鍔犲弻澶ф嫭鍙凤紝鍚﹀垯褰撴垚瀛楃涓插鐞嗐€傚叾浠栫殑闈炵粦瀹氱殑锛岃鐩存帴鏄剧ず鐨勫唴瀹瑰彲鐩存帴鐢ㄥ弻澶ф嫭鍙峰寘浣忓嵆鍙€傚弻澶ф嫭鍙峰唴鍙繘琛岀畝鍗曠殑杩愮畻锛屼絾涓嶆敮鎸丣S 妯℃澘瀛楃涓叉垨鍏朵粬鏂规硶杩愮畻銆?/p>
// Template
<component :name="{{myName}}"> // 缁戝畾鏁版嵁
// 姝e父锛氭覆鏌撳唴瀹? {{Greeting}}
// 姝e父锛氭覆鏌撳唴瀹? {{Greeting + \'World!\'}}
// 鎶ラ敊锛氫笉鏀寔 JS妯℃澘瀛楃涓? {{`${Greeting} World!`}}
// 鎶ラ敊锛氫笉鏀寔 JS 鏂规硶璋冪敤
{{String(Greeting).trim()}}
</component>
// Script
class Foo extends wepy.page {
data = {
myName: \'WePY\',
greetings: \'Hello\',
}
}
1.4 鎿嶄綔鏂规硶鐢?@tap=function
鐨勫舰寮忚繘琛岀粦瀹氥€傚熀鏈笂鎵€鏈夊井淇″師鐢熺殑鏂规硶 bindFn=fn
閮藉彲浠ョ洿鎺ュ啓鎴?@Fn=fn
.
// Template
// 鍘熺敓鐨?bindtap=fn
<view @tap="fn"></view>
// Script
class Foo extends wepy.page {
methods = {
fn: () => {},
}
}
2. Methods & Computed
2.1 class 涓殑methods 涓彧鍖呭惈妯℃澘鐢ㄧ殑浜嬩欢鏂规硶锛屽叾浠栫殑鑷畾涔夋柟娉曞簲璇ヤ笌methods 鏈韩骞崇骇锛屽浜庨《灞傘€?/p>
// Template
<view @tap="fn"></view>
// Script
class Foo extends wepy.page {
methods = {
fn: () => {
this.doSomeThing();
},
}
doSomeThing: () => {}
}
2.2 妯℃澘浜嬩欢鎻愪緵浜嗏€滄柟娉曞悗缂€鈥濅綔涓鸿娉曠硸浠ヤ唬鏇垮師鐢熷啓娉曪紝鏈?code>.default, .stop
鍜?.user
鍚庣紑锛屾瘮杈冨父鐢ㄧ殑鏄?.stop
锛岀浉褰撲簬鍘熺敓鐨?catch
.
// Template
// .default 鍙笉鍐?<view @tap="fn"></view>
// .stop 鐩稿綋浜?catch, 鐐瑰嚮浜嬩欢鍒版缁撴潫锛屼笉浼氬悜涓婂眰缁勪欢鍐掓场
<view @tap.stop="fn"></view>
2.3 姝ゅ杩樻彁渚涗簡computed 鍙妛atcher 鍩烘湰涓嶸ue.js 绫讳技锛屽氨涓嶄粙缁嶄簡~
3. Mixin & Components
3.1 Mixin 鏈夊悗绔紪绋嬬殑灏忎紮浼村簲璇ヤ細姣旇緝鐔熸倝涓€鐐癸紝鍙互灏嗛€氱敤鏂规硶鎻愪緵缁欎笉鍚屽湴鏂逛娇鐢ㄣ€傚湪杩欓噷瀹冭兘鐩存帴璇诲彇鍏辨湁鐨勬暟鎹紙姣斿璇翠粠Redux 閲岃鍙栫殑鍐呭绛夛級浣嗕娇鐢ㄦ椂瑕佹敞鎰忓綋Mixin 涓敤鍒颁簡鏉ヨ嚜Redux 涓殑鏁版嵁鏃讹紝鏁版嵁鏈韩鐨刢onnect 瑕佸湪鍏跺叿浣撳紩鐢ㄥ埌鐨勯〉闈㈤噷闈㈠畾涔夛紝璨屼技Mixin 鏈韩骞朵笉鑳藉皢Redux 涓殑鏁版嵁connect 杩涙潵銆?/p>
3.2 Mixin 涓殑methods 涓笉鑳界洿鎺ヤ娇鐢?this.foo = bar
鍘昏缃〉闈腑鐨勫€硷紝鍥犱负涓婁笅鏂囦笉涓€鑷翠簡涓嶄細鐢熸晥銆?/p>
3.3 Mixin 涓殑鎵ц椤哄簭涓嶸ue.js 涓殑鐩稿弽銆俈ue.js 涓槸鍏堟墽琛孧ixin 涓殑鍑芥暟锛?鍐嶆墽琛岀粍浠舵湰韬殑鍑芥暟銆傝繖閲屾墽琛岄『搴忕浉鍙嶃€?/p>
琛ュ厖锛歏ue.js 涓浜庨挬瀛愬嚱鏁帮紝浼氬厛鎵цMixin 涓殑锛屽啀鎵ц缁勪欢鑷韩鐨勶紱
Vue.js 涓璵ethods 濡傛灉鍜孧ixin 鍚屽悕锛岄偅涔堝彧浼氭墽琛岃嚜韬殑鏂规硶銆?/em>
3.4 缁勪欢鍦?import
鏃朵笉瑕佸甫鍚庣紑鍚嶏細
// Good ;-)
import Xxx from \'../xx\';
// Damned :-(
import Xxx from \'../xx.wpy\';
3.5 鏈€璁╀汉鎳婃伡鐨勪笢瑗挎潵浜嗏€斺€?WePY 涓殑缁勪欢銆傚畠鏄粍浠跺叏鏄€滃崟渚嬧€濈殑锛岃繖鎰忓懗鐫€褰撲綘鍦ㄥ悓涓€涓〉闈腑鍘讳娇鍚屼竴涓粍浠跺娆℃椂锛屾樉绀哄嚭鏉ョ殑閭b€滃鈥濅釜缁勪欢瀹冪粦瀹氱殑鍐呭閮戒細琚洿鏂版垚鏈€鍚庝竴涓紝浣犱笉鑳界粰浠栦滑缁戝畾鍒颁笉鍚岀殑鍐呭涓婏紝浣犵敤缁勪欢鏃跺彧鑳戒韩鍙楀埌鏍峰紡涓婄殑浼樺娍锛屽畬鍏ㄤ笉鐭ユ墍鎯充綍鐗煠封€嶁檪锔?/p>
// Template
<view wx:for="{{list}}">
<comp :number.sync="{{item}}"></comp> // 浣犱篃涓嶈兘杩欐牱鍋氾紝鍥犱负瀹冧笉鎺ュ彈鍙橀噺
</view>
// Script
import Comp from \'../Comp\';
class Foo extends wepy.page {
data = {
list: [1, 2, 3, 4],
}
components = {
comp: Comp,
}
}
闅惧彈 = =||
3.6 瀵逛簬鍘熺敓鍙婇潪鍘熺敓缁勪欢锛屽畠鐨勬ā鏉块€昏緫涔熸€绘槸鈥滅湅涓婂幓涓嶉偅涔堝浐瀹氣€濈殑锛屾瘮濡傝锛?/p>
// 姝g‘ - 鐪佺暐涓?true
<scroll-view scroll-y></scroll-view>
// 閿欒 - 甯冨皵鍊间笉鑳藉甫鎷彿
<scroll-view scroll-y="{{true}}"></scroll-view>
// 姝g‘ - 浼拌杩欓噷瀹為檯涓婂彲鑳?"true" 鏄蹇界暐浜嗙殑
<scroll-view scroll-y="true"></scroll-view>
// 姝g‘ - 浣嗘鏃惰繖涓柟娉曟帴鍙楀埌鐨勭涓€涓弬鏁颁负褰撳墠Class鐨勫疄渚嬶紝鍧戠埞鍟?<view @tap="toggleSomeThing"></view>
// 閿欒 - 甯冨皵鍊艰甯︽嫭鍙?<view @tap="toggleSomeThing(true)"></view>
// 姝g‘
<view @tap="toggleSomeThing({{true}})"></view>
3.7 杩樻湁涓€涓伓鍙戠殑鎯呭喌鏄?wx:if
鏃讹紝class
绛夊叾浠栧睘鎬у伓鍙戜細琚€滃拷鐣ユ帀鈥濄€?/p>
// 姝e父
<view wx:if="{{something === \'foo\'}}" class="foo">
// 鍋跺皵浼氫笉姝e父锛宑lass 琚拷鐣ユ帀浜?<view class="bar" wx:if="{{something === \'bar\'}}">
鎵€浠ユ€讳綋涓婃瘮杈冨缓璁皢鏉′欢鍏堝啓鍑烘潵锛屽悗闈㈠啀鍔犲叾浠栧睘鎬э紝鎴栬€呯洿鎺ョ敤 block
鏍囩鍘讳綔涓烘潯浠跺垽鏂€?/p>
3.8 Page 缁ф壙鑷狢omponent, 浣哖age 鎵╁睍浜嗛〉闈㈡墍鐗规湁鐨?config
閰嶇疆浠ュ強鐗规湁鐨勯〉闈㈢敓鍛藉懆鏈熷嚱鏁扮瓑锛涙墍浠omponent 鍜孭age 涔嬮棿鍩烘湰涓€鏍凤紝浣咰omponent 娌℃湁 onLoad
绛夌敓鍛藉懆鏈熴€?/p>
4. This 鍙婂唴瀹氭柟娉?/h3>
4.1 鏇存柊鏁版嵁鏃跺彲浠ョ洿鎺ョ敤 this.foo = bar
, 涓嶇敤寰俊鍘熺敓鐨?this.setData
鏂规硶銆?/p>
4.2 鎵€鏈夊彲鑳藉彂鐢熷紓姝ョ殑鍦版柟淇敼鏁版嵁鍚庤鎵嬪姩淇冨彂鑴忔暟鎹鏌ユ祦绋嬶紝鍚﹀垯涓嶄細淇冨彂椤甸潰閲嶆覆鏌撱€?br>甯歌鐨勫湴鏂规湁璇锋眰鍚庢洿鏂帮紝setTimeOut, getStorageSync 绛夌瓑~
5. canvas & base64
Canvas 鐨勭浉鍏虫搷浣滃拰寰俊鍘熺敓涓€鏍凤紝鍙傜収 杩欓噷 鍗冲彲锛?/p>
ArrayBuffer 鍜?Base64 浜掕浆锛?/p>
浠?v1.1.0 (2017.03.31)
鐗堟湰灏辨湁杩欎袱涓?API 浜嗭紝鍙互鐩存帴鐢細
wx.arrayBufferToBase64
wx.base64ToArrayBuffer
6. 鍏朵粬锛屼竴鐐瑰紑鍙戝缓璁?/h3>
6.1 灏忕▼搴忓唴閮ㄥ畾涔夌殑瀹炰緥API 閮戒互 $
寮€澶达紝鎵€浠ユ垜浠懡鍚嶆椂涔熶笉搴旇浠?$
寮€澶达紝浠ヤ究鍖哄垎銆?/p>
6.2 鍚屾牱鐨勶紝濡傛灉鐢ㄤ簡Redux, 閭d箞connect 杩涙潵鐨勬柟娉曚篃浼氭槸閫氳繃 this.methods.fn()
鐨勫舰寮忚闂紝寤鸿涔熷緱鍖哄垎寮€姣旇緝濂斤紝姣斿璇撮〉闈㈠強缁勪欢涓殑鏂规硶鍔燽ind 鍓嶇紑銆傚儚杩欐牱锛?/p>
// Redux Action
this.methods.function();
// Page Methods
this.methods.bindFunction();
寮€鍙戜腑鍐欑殑涓€浜涙湁鐢ㄧ殑 Snippets
璺ㄩ〉闈㈤€氳
杩欐槸灏忕▼搴忓師鐢熺殑浠g爜锛岀敤浜庢洿鏂板墠涓€涓〉闈腑鐨凞ata 鍊?/p>
搴旂敤鍦烘櫙姣斿璇存湁涓€涓〃鍗曠被鐨勯〉闈紝鍏朵腑鐨勬煇涓瓧娈靛彲浠ョ偣鍒板彟澶栦竴涓叏灞忕殑鐣岄潰鍘荤紪杈?/p>
鏀瑰畬浜嗕繚瀛樺悗浼氬洖鍒板綋鍓嶇殑椤甸潰涓户缁紪杈戝叾浠栫殑瀛楁
// 鑾峰彇褰撳墠椤甸潰鏍堢殑瀹炰緥 <Array>
let crtPage = getCurrentPages();
// 寰楀埌涓婁竴涓〉闈㈠疄渚?<Object>
let prevPage = crtPage[crtPage.length - 2];
// 璁剧疆鍓嶄竴涓〉闈腑鐨勬暟鎹?prevPage.setData({note: this.value});
/*
* 杩欎釜鍋氭硶鍙互姝e父璁剧疆鍓嶄竴涓〉闈腑鐨凞ata 鐨勫€硷紝
* 浣嗗鏋滈偅涓〉闈腑鐨勯偅涓狣ata 鏄敤浣淧rops 浼犵粰缁勪欢鐨勮瘽
* 缁勪欢涓殑鍊煎苟涓嶄細璺熺潃鏇存柊鎴愭柊鐨勫€? */
姝e垯瑙f瀽鍩庡競瀛楃涓诧紝鐢ㄤ簬寰俊鍘熺敓鐪佸競閫夋嫨缁勪欢
鍥犱负鏈変釜椤圭洰鐨勫悗绔槸淇濆瓨鐨勭被浼?"涓婃捣甯備笂娴峰競寰愭眹鍖? 鐨勫€?/p>
浣嗗井淇$殑缁勪欢浣跨敤鐨剉alue 鍗存槸绫讳技 [\'涓婃捣甯?, \'涓婃捣甯?, \'寰愭眹鍖?] 杩欐牱鐨勬暟缁?/p>
涓轰簡淇濊瘉淇敼鏃惰兘姝g‘鏄剧ず涓婃璁剧疆鐨勫唴瀹规墍浠ュ氨鏈変簡杩欎箞涓€涓笢瑗?/p>
/*
* Parse String to Wechat City Array
*
* @param:
* city <String>: \'涓婃捣甯備笂娴峰競寰愭眹鍖?
*
* @return:
* <Array> [\'涓婃捣甯?, \'涓婃捣甯?, \'寰愭眹鍖?]
*/
const parseRegion = (city) => {
let str = city;
let region = [];
let reg = [
/\\S[^鐪亅甯倈鍖篯+[鐪亅甯倈鍖篯/,
/\\S[^甯倈鍖篯+[甯倈鍖篯/,
/\\S[^甯倈鍖簗鍘縘+[甯倈鍖簗鍘縘/,
];
for (let r of reg) {
const rs = r.exec(str);
if (rs !== null) {
region.push(rs[0]);
str = str.replace(rs[0], \'\');
}
}
return region;
};
URL 鍙傛暟搴忓垪鍖?/h3>
鐢ㄩ€旓細褰撳皬绋嬪簭闇€瑕佹爮鎴搷浣滄椂锛屼复鏃朵繚瀛樹紶鍏ョ殑鍙傛暟
// onLoad(op) { this.op = op; }
// reLaunch 鏃?url = some-url + \'?\' + this.serializer(this.op)
serializer = (data = {}) => (
Object.entries(data).map(
([key, value]) => (
value !== undefined
? `${key}=${encodeURIComponent(value)}`
: \'\'
)
)
.filter((item) => (item))
.join(\'&\')
);
以上是关于灏忕▼搴忔鏋禬ePY 浠庡叆闂ㄥ埌鏀惧純韪╁潙鍚堥泦的主要内容,如果未能解决你的问题,请参考以下文章
Java浠庡叆闂ㄥ埌瀹炴垬涔嬶紙20锛夊瓧绗︿覆涔?鏌ユ壘瀛楃涓叉渶鍚庝竴娆″嚭鐜扮殑浣嶇疆
Git 宸ヤ綔娴佺▼锛汫raphQL 浠庡叆闂ㄥ埌瀹炶返锛汚ngular 9.0 鍙戝竷锛両vy 姝e紡鎶佃揪