var vm = new Vue ({
el:".container",
data:{
addressList:[],
showLength : 3
},
mounted:function () {
this.$nextTick(function () {
this.getAddressList();
})
},
computed:{
filterAddress : function () {
return this.addressList.slice(0, this.showLength);
}
},
methods: {
getAddressList : function () {
this.$http.get("data/address.json").then(res=>{
if(res.body.status == 0){
this.addressList = res.body.result;
}
})
},
moreAddress:function () {
this.showLength = this.addressList.length;
},
lessAddress:function () {
this.showLength = 3;
}
}
});
<div class="moreAddress" @click="moreAddress">
<span @click="moreAddress" v-if="showLength < addressList.length">更多地址<i class="fa fa-angle-down"></i></span>
<span @click="lessAddress" v-if="showLength == addressList.length">收起地址<i class="fa fa-angle-up"></i></span>
</div>