最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

vue resource發(fā)送請求的幾種方式

 更新時(shí)間:2019年09月30日 09:45:06   作者:angle-xiu  
這篇文章主要介紹了vue resource發(fā)送請求的幾種方式,代碼簡單易懂,非常不錯(cuò),具有一定的參考借鑒價(jià)值,需要的朋友可以參考下

vue resource發(fā)送請求,代碼如下所示;

<!DOCTYPE html>
<html>
<head>
  <title>vue-resource</title>
  <meta charset="utf-8">
</head>

<body>
  <div id="app">
    <input type="button" value="get請求" @click="getInfo">
    <input type="button" value="post請求" @click="postInfo">
  </div>
</body>
<!-- 基于vue-resource實(shí)現(xiàn)get post請求 也可利用axios第三方包實(shí)現(xiàn)-->
<script src="https://cdn.staticfile.org/vue/2.6.10/vue.js"></script>
<script src="https://cdn.staticfile.org/vue-resource/1.5.1/vue-resource.js"></script>
<script>
  // vue-promise是基于vue的,所以引入CDN庫時(shí)需要注意順序,應(yīng)先引入vue
  let vm = new Vue({
    el: "#app",
    data:{
    },
    methods:{//vue-resource發(fā)送請求是基于promise的
      getInfo(){
        this.$http.get('https://www.easy-mock.com/mock/5d537a1cf651bc6ff265fb77/example/result/cart.json') 
        .then(res=>{
          console.log(res);
        })
      },
      postInfo(){
        this.$http.post('https://www.easy-mock.com/mock/5d537a1cf651bc6ff265fb77/example/upload',{},{
          emulateJSON:true//設(shè)置這個(gè)參數(shù)相當(dāng)于application/x-www-form-urlencoded,由于手動提交請求沒有默認(rèn)表單格式,需要設(shè)置發(fā)送的數(shù)據(jù)格式
        })
        .then(res=>{
          console.log(res.body);
        })
      },
      }
  });
</script>
</html>

知識點(diǎn)擴(kuò)展;vue-resource請求的幾種方式

安裝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 : "數(shù)據(jù)錯(cuò)誤",
      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){
    })
 
 },

總結(jié)

以上所述是小編給大家介紹的vue resource發(fā)送請求的幾種方式,希望對大家有所幫助,如果大家有任何疑問請給我留言,小編會及時(shí)回復(fù)大家的。在此也非常感謝大家對腳本之家網(wǎng)站的支持!
如果你覺得本文對你有幫助,歡迎轉(zhuǎn)載,煩請注明出處,謝謝!

相關(guān)文章

最新評論

和静县| 阿勒泰市| 云阳县| 城步| 通山县| 永新县| 曲松县| 门头沟区| 武冈市| 朔州市| 喜德县| 和林格尔县| 竹山县| 邢台县| 元谋县| 荣成市| 灯塔市| 陆川县| 顺义区| 兰考县| 鹿泉市| 彩票| 越西县| 芦山县| 蕉岭县| 清镇市| 平遥县| 比如县| 安溪县| 巴彦淖尔市| 汝阳县| 天长市| 巴东县| 赤壁市| 邓州市| 灵川县| 九江市| 镇康县| 贞丰县| 榕江县| 公主岭市|