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

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

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

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

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

<body>
  <div id="app">
    <input type="button" value="get請(qǐng)求" @click="getInfo">
    <input type="button" value="post請(qǐng)求" @click="postInfo">
  </div>
</body>
<!-- 基于vue-resource實(shí)現(xiàn)get post請(qǐng)求 也可利用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ā)送請(qǐng)求是基于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,由于手動(dòng)提交請(qǐng)求沒有默認(rèn)表單格式,需要設(shè)置發(fā)送的數(shù)據(jù)格式
        })
        .then(res=>{
          console.log(res.body);
        })
      },
      }
  });
</script>
</html>

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

安裝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ā)送請(qǐng)求的幾種方式,希望對(duì)大家有所幫助,如果大家有任何疑問請(qǐng)給我留言,小編會(huì)及時(shí)回復(fù)大家的。在此也非常感謝大家對(duì)腳本之家網(wǎng)站的支持!
如果你覺得本文對(duì)你有幫助,歡迎轉(zhuǎn)載,煩請(qǐng)注明出處,謝謝!

相關(guān)文章

最新評(píng)論

芜湖市| 观塘区| 南康市| 洞口县| 南通市| 遵义市| 金平| 常德市| 金坛市| 宜春市| 瑞金市| 崇州市| 溧阳市| 壶关县| 东平县| 永顺县| 六安市| 宜昌市| 丽江市| 田林县| 乌兰浩特市| 沁源县| 抚顺县| 务川| 淮阳县| 新蔡县| 德州市| 剑河县| 曲麻莱县| 德庆县| 息烽县| 芜湖市| 伊宁市| 延安市| 信丰县| 青神县| 乳山市| 甘孜县| 辽宁省| 旺苍县| 白水县|