亚洲乱码中文字幕综合,中国熟女仑乱hd,亚洲精品乱拍国产一区二区三区,一本大道卡一卡二卡三乱码全集资源,又粗又黄又硬又爽的免费视频

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

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

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實現(xiàn)get post請求 也可利用axios第三方包實現(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庫時需要注意順序,應(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è)置這個參數(shù)相當(dāng)于application/x-www-form-urlencoded,由于手動提交請求沒有默認(rèn)表單格式,需要設(shè)置發(fā)送的數(shù)據(jù)格式
        })
        .then(res=>{
          console.log(res.body);
        })
      },
      }
  });
</script>
</html>

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

相關(guān)文章

  • electron + vue項目實現(xiàn)打印小票功能及實現(xiàn)代碼

    electron + vue項目實現(xiàn)打印小票功能及實現(xiàn)代碼

    這篇文章主要介紹了electron + vue項目實現(xiàn)打印小票功能,需要的朋友可以參考下
    2018-11-11
  • 導(dǎo)致VUE頁面不刷新的問題分析及解決方法

    導(dǎo)致VUE頁面不刷新的問題分析及解決方法

    由于 Vue 會在初始化實例時對 property 執(zhí)行 getter/setter 轉(zhuǎn)化,所以 property 必須在 data 對象上存在才能讓 Vue 將它轉(zhuǎn)換為響應(yīng)式的,這篇文章主要介紹了導(dǎo)致VUE頁面不刷新的問題分析及解決方法,需要的朋友可以參考下
    2024-04-04
  • Vue一個案例引發(fā)的遞歸組件的使用詳解

    Vue一個案例引發(fā)的遞歸組件的使用詳解

    這篇文章主要介紹了Vue一個案例引發(fā)的遞歸組件的使用,本文主要給大家展示如何在項目中使用遞歸組件,本文給大家介紹的非常詳細(xì),具有一定的參考借鑒價值,需要的朋友可以參考下
    2018-11-11
  • Vue+tracking.js 實現(xiàn)前端人臉檢測功能

    Vue+tracking.js 實現(xiàn)前端人臉檢測功能

    這篇文章主要介紹了Vue+tracking.js 實現(xiàn)前端人臉檢測功能,本文通過實例代碼給大家介紹的非常詳細(xì),對大家的學(xué)習(xí)或工作具有一定的參考借鑒價值,需要的朋友可以參考下
    2020-04-04
  • 不同場景下Vue中虛擬列表實現(xiàn)

    不同場景下Vue中虛擬列表實現(xiàn)

    虛擬列表用來解決大數(shù)據(jù)量數(shù)據(jù)渲染問題,由于一次性渲染性能低,所以誕生了虛擬列表渲染,下面我們就來學(xué)習(xí)一下不同場景下Vue中虛擬列表是如何實現(xiàn)的吧
    2023-10-10
  • vue中提示$index is not defined錯誤的解決方式

    vue中提示$index is not defined錯誤的解決方式

    這篇文章主要介紹了vue中提示$index is not defined錯誤的解決方式,具有很好的參考價值,希望對大家有所幫助。一起跟隨小編過來看看吧
    2020-09-09
  • element?實現(xiàn)導(dǎo)航欄收起展開功能及思路

    element?實現(xiàn)導(dǎo)航欄收起展開功能及思路

    這篇文章主要介紹了element?實現(xiàn)導(dǎo)航欄收起展開功能,實現(xiàn)思路先給 el-menu加上 :collapse="isCollapse" 屬性,這個屬性也是 element 上的一個參數(shù),意思為是否開啟折疊動畫,在 data 中定義 isCollapse ,用 true 和 false 控制展開與收起,需要的朋友可以參考下
    2023-01-01
  • Vue如何防止按鈕重復(fù)點擊方案詳解

    Vue如何防止按鈕重復(fù)點擊方案詳解

    這篇文章主要介紹了vue 如何處理防止按鈕重復(fù)點擊問題,具有很好的參考價值,希望對大家有所幫助。如有錯誤或未考慮完全的地方,望不吝賜教
    2022-12-12
  • elementui使用el-upload組件如何實現(xiàn)自定義上傳

    elementui使用el-upload組件如何實現(xiàn)自定義上傳

    這篇文章主要介紹了elementui使用el-upload組件如何實現(xiàn)自定義上傳,具有很好的參考價值,希望對大家有所幫助。如有錯誤或未考慮完全的地方,望不吝賜教
    2022-08-08
  • vue中axios利用blob實現(xiàn)文件瀏覽器下載方式

    vue中axios利用blob實現(xiàn)文件瀏覽器下載方式

    這篇文章主要介紹了vue中axios利用blob實現(xiàn)文件瀏覽器下載方式,具有很好的參考價值,希望對大家有所幫助,如有錯誤或未考慮完全的地方,望不吝賜教
    2024-05-05

最新評論