vue界面初始化查詢列表的方法之購物車案例-------支付界面


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;

        }

      })

    }

  }  

 

})

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM