new Vue({
el:".container",
data:{
addressList:[],
limitNum:3,
currentIndex:0, //用於選擇地址,調用:class="{'check':index==currentIndex}" @click="currentIndex=index"
shippingMethod:1,//使用見文檔底部圖片
},
mounted:function(){
this.$nextTick(function(){
getAddressList()
})
},
computed:{//computed一般用於實時計算
filterAddress:function(){ for循環中的過濾器,初始化時只顯示三個地址。調用 v-for = "(item ,index) in filterAddress"
return this.addressList.slice(0,this.limitNum); 截取前3個
}
},
methods:{
getAddressList:function(){
this.$http.get("data/address.json").then(response=>{
var res =response.data;
if(res.status == "0"){
this.addressList = res.result
}
})
},
loadMord:function(){ //顯示全部地址
this.limitNum = this.addressList.length
},
setDefault:function(addressId){
this.addressList.forEach((address,index)=>{
if(address.addressId==addressId){
address.isDefault = true;
}else{
address.isDefault = false;
}
})
}
}
})