美文网首页
vue-resource请求的几种方式

vue-resource请求的几种方式

作者: 阳光之城alt | 来源:发表于2018-12-20 14:31 被阅读0次
    image.png
    安装import VueResource from 'vue-resource'
    Vue.use(VueResource)
    
    get //获取
    getdesignatepl({commit,rootState}){
      //  console.log("ppppp")
        let designate_list = `schedule-plan-configuration`;
        Vue.http.get(api.get(designate_list),{headers:rootState.headers}).then(function(response){
            let pup=response.data.data;
          // console.log(response)
        },function(response){
          // console.log("pl")
          var tipsObj = {
                title : "数据错误",
                flag: true,
                type: 4,
                btnGroup:['ook']
            }
            commit('popup',tipsObj,{root:true});
        })
      }
    
    post//新增  
     setAdd({commit,rootState,state,dispatch,context},mss){
      Vue.http.post(api.save('schedule-plan-configuration'),mss,{headers:rootState.headers}).then(function(response){
         dispatch("getdesignatepl")
          commit('popup',titleObj,{root:true});
        },function(response){
          if(response.status == 422){
              commit('popup',tipsObj,{root:true});
        }
        })
      },
    
      //删除
      BrDelete(context,obj){
        let br_delete_put_data = `schedule-plan-configuration/${obj.id}`
        Vue.http.delete(api.get(br_delete_put_data),{headers:context.rootState.headers}).then(function(response){ 
          context.dispatch("getdesignatepl");
        },function(response){
            // console.log(response); 
            if(response.status == 401 || response.status == 500){
                var tipsObj = {
                    status: response.status,
                    flag: true,
                    type: 4,
                    btnGroup:['ook']
                }
                context.commit('popup',tipsObj,{root:true});
                return;
            }
        })
      },
    
    
      // 跟新
      getEntrySales({commit,rootState,dispatch,context},obj){
        // console.log(obj.id)
          Vue.http.put(api.update(`schedule-plan-configuration/${obj.id}`),obj, 
       {headers:rootState.headers}).then(function(response){
            dispatch("getdesignatepl");
            },function(response){
            })
      
      },
    
    

    相关文章

      网友评论

          本文标题:vue-resource请求的几种方式

          本文链接:https://www.haomeiwen.com/subject/rxyykqtx.html