12-----鎸囦护绯荤粺浠嬬粛
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了12-----鎸囦护绯荤粺浠嬬粛相关的知识,希望对你有一定的参考价值。
鏍囩锛?a href='http://www.mamicode.com/so/1/%e6%95%b0%e7%bb%84' title='鏁扮粍'>鏁扮粍
浜嬩欢鐩戝惉 als 鐩戝惉 spl time 鎺ユ敹 ORC 榧犳爣鎮仠 鎵€璋撴寚浠ょ郴缁燂紝澶у鍙互鑱旀兂鍜变滑鐨刢md鍛戒护琛屽伐鍏凤紝鍙鎴戣緭鍏ヤ竴鏉℃纭殑鎸囦护锛岀郴缁熷氨寮€濮嬪共娲讳簡銆?/p>
鍦╲ue涓紝鎸囦护绯荤粺锛岃缃竴浜涘懡浠や箣鍚庯紝鏉ユ搷浣滄垜浠殑鏁版嵁灞炴€э紝骞跺睍绀哄埌鎴戜滑鐨凞OM涓娿€?/p>
OK锛屾帴涓嬫潵鎴戜滑涓€涓€浠嬬粛鎴戜滑鐨勬寚浠ょ郴缁熺殑鐢ㄦ硶銆?/p>
涓€銆佹潯浠舵覆鏌?/span>
1銆乿-if
琛ㄧず鏉′欢娓叉煋
鍦╲ue涓紝鎴戜滑浣跨敤v-if鎸囦护锛屽皢褰撳墠鐨刣om鍏冪礌璁剧疆
<p v-if = 鈥榮how鈥?/span>>鏄剧ず</p>
娉ㄦ剰锛歴how鍙橀噺锛屾槸鏁版嵁灞炴€т腑瀛樺偍鐨勫€笺€傝涔堢湡(true)瑕佷箞鍋?false)銆傝灞炴€у€间负true鐨勬椂鍊欙紝p鏍囩鏄剧ず锛屽弽涔嬪垯涓嶆樉绀恒€?/p>
涔熷彲浠ユ坊鍔犱竴涓獀-else鍧椼€?/p>
<divv-if = 鈥榮how鈥?/span>>鏄剧ず</div>
<divv-else>闅愯棌</div>
鍙﹀鎴戜滑鍙戠幇锛寁-if灏嗙涓€涓猟iv娓叉煋锛屽苟娌℃湁灏嗙浜屼釜div娓叉煋銆?/p>
鍙﹀杩樻湁v-else-if鍧楋紝瀹冩槸2.1.0鏂板鐨勩€?/p>
<div v-if="type === 鈥榯hunder鈥?gt;
鎵撻浄
</div>
<div v-else-if="type === 鈥榬ain鈥?/span>>
涓嬮洦
</div>
<div v-else>
闆烽樀闆?</div>
2銆乿-show
鍙︿竴涓敤浜庢牴鎹潯浠跺睍绀哄厓绱犵殑閫夐」鏄?nbsp;v-show
鎸囦护銆傜敤娉曞ぇ鑷翠竴鏍凤細
<p v-show=鈥榦k鈥?/span>>缃戠珯瀵艰埅</p>
濡傛灉ok鏁版嵁灞炴€у€间负false銆傞偅涔堟樉绀虹粨鏋滃涓?/p>
涓嶅悓鐨勬槸甯︽湁 v-show
鐨勫厓绱犲缁堜細琚覆鏌撳苟淇濈暀鍦?DOM 涓€?code>v-show
鍙槸绠€鍗曞湴鍒囨崲鍏冪礌鐨?CSS 灞炴€?nbsp;display
娉ㄦ剰锛歷-show涓嶆敮鎸乿-else鍧?/p>
3銆乿-if vs v-show
v-if
鏄€滅湡姝b€濈殑鏉′欢娓叉煋锛屽洜涓哄畠浼氱‘淇濆湪鍒囨崲杩囩▼涓潯浠跺潡鍐呯殑浜嬩欢鐩戝惉鍣ㄥ拰瀛愮粍浠堕€傚綋鍦拌閿€姣佸拰閲嶅缓銆?/p>
v-if
涔熸槸鎯版€х殑锛氬鏋滃湪鍒濆娓叉煋鏃舵潯浠朵负鍋囷紝鍒欎粈涔堜篃涓嶅仛鈥斺€旂洿鍒版潯浠剁涓€娆″彉涓虹湡鏃讹紝鎵嶄細寮€濮嬫覆鏌撴潯浠跺潡銆?/p>
鐩告瘮涔嬩笅锛?code>v-show
灏辩畝鍗曞緱澶氣€斺€斾笉绠″垵濮嬫潯浠舵槸浠€涔堬紝鍏冪礌鎬绘槸浼氳娓叉煋锛屽苟涓斿彧鏄畝鍗曞湴鍩轰簬 CSS 杩涜鍒囨崲銆?/p>
涓€鑸潵璇达紝v-if
鏈夋洿楂樼殑鍒囨崲寮€閿€锛岃€?nbsp;v-show
鏈夋洿楂樼殑鍒濆娓叉煋寮€閿€銆傚洜姝わ紝濡傛灉闇€瑕侀潪甯搁绻佸湴鍒囨崲锛屽垯浣跨敤 v-show
杈冨ソ锛涘鏋滃湪杩愯鏃舵潯浠跺緢灏戞敼鍙橈紝鍒欎娇鐢?nbsp;v-if
杈冨ソ銆?/p>
4銆乿i-if涓巚-for涓€璧蜂娇鐢?nbsp;
v-for 鎸囦护锛屽悗闈㈤┈涓婁粙缁嶅埌銆?/p>
褰?nbsp;v-if 涓?nbsp;v-for 涓€璧蜂娇鐢ㄦ椂锛?strong>v-for
鍏锋湁姣?v-if 鏇撮珮鐨勪紭鍏堢骇銆?/p>
浜屻€乧lass涓巗tyle缁戝畾
v-bind
鎿嶄綔鍏冪礌鐨?class 鍒楄〃鍜屽唴鑱旀牱寮忔槸鏁版嵁缁戝畾鐨勪竴涓父瑙侀渶姹傘€傚洜涓哄畠浠兘鏄睘鎬с€傛墍浠ユ垜浠彲浠ョ敤 v-bind
澶勭悊瀹冧滑锛氬彧闇€瑕侀€氳繃琛ㄨ揪寮忚绠楀嚭瀛楃涓茬粨鏋滃嵆鍙€備笉杩囷紝瀛楃涓叉嫾鎺ラ夯鐑︿笖鏄撻敊銆傚洜姝わ紝鍦ㄥ皢 v-bind
鐢ㄤ簬 class
鍜?nbsp;style
鏃讹紝Vue.js 鍋氫簡涓撻棬鐨勫寮恒€傝〃杈惧紡缁撴灉鐨勭被鍨嬮櫎浜嗗瓧绗︿覆涔嬪锛岃繕鍙互鏄璞℃垨鏁扮粍銆?/p>
姣斿鎴戜滑鍙互
缁戝畾瀛楃涓?nbsp;
<span v-bind:title=鈥榯ime鈥?/span>>榧犳爣鎮仠鍑犵鍚庡綋鍓嶆椂闂?span style="color: #0000ff"></span>
data:{ time: `椤甸潰鍔犺浇浜?{new Date().toLocaleString()}`, }
缁戝畾html Class
鎴戜滑鍦╦s涓父鐢ㄦ搷浣渄om鐨刢ss鏍峰紡灞炴€х殑鏂规硶鏈夊緢澶氾紝鍦╲ue涓彲浠ョ洿鎺ヤ娇鐢╲-bind:class鏉ョ粰姣忎釜鏍囩鍏冪礌娣诲姞class銆?/p>
瀵硅薄璇硶
鎴戜滑鍙互浼犵粰 v-bind:class
涓€涓璞★紝浠ュ姩鎬佸湴鍒囨崲 class锛?/p>
... data:{ isRed:true }
<div v-bind:class=鈥榹box1:isRed}鈥?/span>></div>
鏁堟灉濡備笅锛?/p>
濡傛灉鏈夋寜閽殑璇濓紝鎴戜滑鍙互閫氳繃鐐瑰嚮鎸夐挳鍔ㄦ€佺殑鍒囨崲class銆傛澶栵紝v-bind:class
鎸囦护涔熷彲浠ヤ笌鏅€氱殑 class 灞炴€у叡瀛?/p>
<div class=鈥榓鈥?v-bind:class=鈥榹box1:isRed,box2:isGreen}鈥?/span>></div>
鍜屽涓媎ata锛?/p>
data:{ isRed:true, isGreen:fasle }
鏁堟灉濡備笅锛?/p>
鏈夎繖涔堜竴涓猚ss鏍峰紡锛?/p>
.box1{ width: 100px; height: 100px; background-color: red; } .box2{ width: 100px; height: 100px; background-color: green; }
閭d箞鎴戜滑鍦ㄦ枃妗g粨鏋勪腑鍙互鍔犱竴涓?/p>
<button v-on:click =鈥榗lickHandler鈥?/span>>鍒囨崲</button>
浣跨敤v-on缁戝畾js涓墍鏈夌殑浜嬩欢銆傝繖閲屾垜浠槸缁戝畾浜嗙偣鍑讳簨浠躲€傦紙鍚庨潰浼氫粙缁嶏級
鍦ㄥ疄渚嬪寲options鍙傛暟涓坊鍔犲涓嬮厤缃細
methods:{ clickHandler(){ this.isGreen = !this.isGreen; } }
鏁扮粍璇硶
鎴戜滑鍙互鎶婁竴涓暟缁勪紶缁檝-bind:class,浠ュ簲鐢ㄤ竴涓?class 鍒楄〃锛?/p>
<div v-bind:class="[activeClass, errorClass]"></div>
data: { activeClass: 鈥榓ctive鈥? errorClass: 鈥榯ext-danger鈥?}
娓叉煋涓猴細
<div class="active text-danger"></div>
濡傛灉浣犱篃鎯虫牴鎹潯浠跺垏鎹㈠垪琛ㄤ腑鐨?class锛屽彲浠ョ敤涓夊厓琛ㄨ揪寮忥細
<div v-bind:class="[isActive ? activeClass : 鈥樷€? errorClass]"></div>
杩欐牱鍐欏皢濮嬬粓娣诲姞 errorClass
锛屼絾鏄彧鏈夊湪 isActive
鏄?true鏃舵墠娣诲姞 activeClass
銆?/p>
涓嶈繃锛屽綋鏈夊涓潯浠?class 鏃惰繖鏍峰啓鏈変簺绻佺悙銆傛墍浠ュ湪鏁扮粍璇硶涓篃鍙互浣跨敤瀵硅薄璇硶锛?/p>
<div v-bind:class="[{ active: isActive }, errorClass]"></div>
涓夈€佷簨浠跺鐞?/span>
鐩戝惉浜嬩欢
鍙互鐢?nbsp;v-on
鎸囦护鐩戝惉 DOM 浜嬩欢锛屽苟鍦ㄨЕ鍙戞椂杩愯涓€浜?JavaScript 浠g爜銆?/p>
1 <div id=鈥榓pp鈥?/span>> 2 <button v-on:click = 鈥榗ount+=1鈥?/span>>鍔爗{count}}</button> 3 <p>鐐逛簡{{count}}娆?span style="color: #0000ff"></p> 4 </div>
var app = new Vue({ el:鈥?app鈥? data:{ count:0 } })
缁撴灉涓猴細褰撴垜鐐瑰嚮鐨勬寜閽殑鏃跺€欙紝涓嬮潰p鏍囩鐨勬暟鎹篃浼氬彂鐢熷彉鍖栵紝鍚屾椂button鐨勬枃瀛椾篃浼氬彂鐢熷彉鍖栥€?/p>
浜嬩欢澶勭悊鏂规硶
鐒惰€岃澶氫簨浠跺鐞嗛€昏緫浼氭洿涓哄鏉傦紝鎵€浠ョ洿鎺ユ妸 javascript 浠g爜鍐欏湪 v-on
鎸囦护涓槸涓嶅彲琛岀殑銆傚洜姝?nbsp;v-on
杩樺彲浠ユ帴鏀朵竴涓渶瑕佽皟鐢ㄧ殑鏂规硶鍚嶇О
1 <div id=鈥榓pp鈥?/span>> 2 <button v-on:click = 鈥榗ountClick鈥?/span>>鍔爗{count}}</button> 3 <p>鐐逛簡{{count}}娆?span style="color: #0000ff"></p> 4 </div>
以上是关于12-----鎸囦护绯荤粺浠嬬粛的主要内容,如果未能解决你的问题,请参考以下文章
榛戣嫻鏋滃紑鑽掕绯荤粺绡? 瓒呰缁嗙殑绾噣 MacOS 瀹夎娴佺▼