接收后台数据

在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>

 

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