接收後臺數據

在api.js中封裝請求接口

 findBanquetingHall(data){
        return axios.post("/business/findBanquetingHall",data)
    },

在.vue中導入vuex的Mapset

import {mapState} from 'vuex'

在.vue   data同級寫computed

computed:{
      ...mapState({
          hoteldescribe_id:state=>state.loginuser.wenShopid,   //需要用到的酒店id
          student_user_id:state=>state.loginuser.countser      //需要用到的客戶id
      })
    },

寫一個方法,在頁面渲染完成後執行方法

 methods:{
        getapp(){

        }
    },
    mounted(){
        this.getapp();
    }

在方法中寫

 methods:{
        getapp(){
            this.axios.findBanquetingHall({     //剛纔封裝的axios請求名稱
                     //寫參數
            }).then(res=>{
                //請求成功時執行
            }).catch(res=>{
                //請求失敗時執行
            })
        }
    },

例子:

getapp(){
            this.axios.findBanquetingHall({     
                hoteldescribe_id:this.hoteldescribe_id     //通過酒店id查詢   如果沒有參數就不寫
            }).then(res=>{
                this.alldata=res.data;
                console.log(res.data)
            }).catch(res=>{
                
            })
        }

注:如果需要循環綁定則如下(空數組dataarry=[ ])

<div v-for="item in dataarry" :key='item.id' @click=add(item.bh_id)></div>  //dataarry爲自己定義的寇數組
<div>{{item.bh_name}}</div>

如果不需要循環綁定,直接定義一個dataarry='';,綁定就可以了

<div>{{dataarry.bh_name}}</div>

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章