最近碰到一個由於要根據權限來給一個按鈕變成不一樣功能,html
簡單寫出3個按鈕而後用v-if也能實現這個功能,可是在加載頁面時,若是延遲太高則會把按鈕按照DOM順序加載出來,這是個很很差的效果app
思索了下,把三個功能分開寫,目前但說能達到需求,但我的感受還不是最好解決辦法,在此記錄下來以待未來發現更好辦法ui
<div class="btn60"> <span v-on:click="reserveMainLink()" :class="{'weui_btn':items.msg!=3,'weui_btn_primary':items.msg==1,'weui_btn_warn':items.msg==2}" > <span v-show="items.msg==1">當即預定</span> <span v-show="items.msg==2">已預定</span> <span v-show="items.msg==3">已過時</span> </span> </div>
ticketdata = {"travelId":"46523","travelName":"揚州88風景區","area":"12","imgUrl":"http://***/img/jq/Upload/Content/Thumb/16/09/22/45731474528552.gif","travelArea":"揚州市區東北郊88鎮88路1號。","areaName":"江蘇","price":"45","lotteryCode":null,"payCode":null,"expireTime":null,"endexpireTime":null,"reservetime":null,"username":null,"type":null,"otherOrderId":null,"addtime":null,"notice":null,"enterpark":null,"areaId":null,"useTime":null,"imageUrl":null,"useInfo":null,"endreserveTime":null,"phone":null,"cardId":null,"worker":null,"msg":"1"}; App.items= ticketdata; var App = new Vue({ el:"#app", data:{ items:[] }, methods:{ reserveMainLink:function(){ if( this.items.msg == 1 ){ //提交預定 var payCode = $("#payCode").val(); window.location.href="order?payCode"+payCode; }else if( this.items.msg == 2 ){ //已預定門票詳情 window.location.href="orderDetails.html"; } } } })