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

vue基礎(chǔ)之使用get、post、jsonp實(shí)現(xiàn)交互功能示例

 更新時(shí)間:2019年03月12日 11:48:16   作者:白楊-M  
這篇文章主要介紹了vue基礎(chǔ)之使用get、post、jsonp實(shí)現(xiàn)交互功能,結(jié)合實(shí)例形式分析了vue.js中g(shù)et、post及jsonp針對(duì)本地文件、網(wǎng)絡(luò)接口實(shí)現(xiàn)交互功能相關(guān)操作技巧,需要的朋友可以參考下

本文實(shí)例講述了vue基礎(chǔ)之使用get、post、jsonp實(shí)現(xiàn)交互功能。分享給大家供大家參考,具體如下:

一、如果vue想做交互,引入: vue-resouce

二、get方式

1、get獲取一個(gè)普通文本數(shù)據(jù):

<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <title></title>
  <style>
  </style>
  <script src="vue.js"></script>
  <script src="vue-resource.js"></script>
  <script>
    window.onload=function(){
      new Vue({
        el:'body',
        data:{
        },
        methods:{
          get:function(){
            this.$http.get('a.txt').then(function(res){
              alert(res.status);//成功
              alert(res.data);
            },function(res){
              alert(res.status);//失敗返回
              alert(res.data);
            });
          }
        }
      });
    };
  </script>
</head>
<body>
  <input type="button" value="按鈕" @click="get()">
</body>
</html>

2、get給服務(wù)發(fā)送數(shù)據(jù):

<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <title></title>
  <style>
  </style>
  <script src="vue.js"></script>
  <script src="vue-resource.js"></script>
  <script>
    window.onload=function(){
      new Vue({
        el:'body',
        data:{
        },
        methods:{
          get:function(){
            this.$http.get('get.php',{
              a:1,
              b:2
            }).then(function(res){
              alert(res.data);
            },function(res){
              alert(res.status);
            });
          }
        }
      });
    };
  </script>
</head>
<body>
  <input type="button" value="按鈕" @click="get()">
</body>
</html>

三、post方式

<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <title></title>
  <style>
  </style>
  <script src="vue.js"></script>
  <script src="vue-resource.js"></script>
  <script>
    window.onload=function(){
      new Vue({
        el:'body',
        data:{
        },
        methods:{
          get:function(){
            this.$http.post('post.php',{
              a:1,
              b:20
            },{
              emulateJSON:true
            }).then(function(res){
              alert(res.data);
            },function(res){
              alert(res.status);
            });
          }
        }
      });
    };
  </script>
</head>
<body>
  <input type="button" value="按鈕" @click="get()">
</body>
</html>

四、jsonp方式

獲取百度接口

查看響應(yīng)數(shù)據(jù)

jsonp請(qǐng)求百度接口

<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <title></title>
  <style>
  </style>
  <script src="vue.js"></script>
  <script src="vue-resource.js"></script>
  <script>
    window.onload=function(){
      new Vue({
        el:'body',
        data:{
        },
        methods:{
          get:function(){
            this.$http.jsonp('https://sp0.baidu.com/5a1Fazu8AA54nxGko9WTAnF6hhy/su',{
              wd:'a'
            },{
              jsonp:'cb'//回調(diào)函數(shù)名稱
            }).then(function(res){
              alert(res.data.s);
            },function(res){
              alert(res.status);
            });
          }
        }
      });
    };
  </script>
</head>
<body>
  <input type="button" value="按鈕" @click="get()">
</body>
</html>

jsonp請(qǐng)求360接口

<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <title></title>
  <style>
  </style>
  <script src="vue.js"></script>
  <script src="vue-resource.js"></script>
  <script>
    window.onload=function(){
      new Vue({
        el:'body',
        data:{
        },
        methods:{
          get:function(){
            this.$http.jsonp('https://sug.so.#/suggest',{
              word:'a'
            }).then(function(res){
              alert(res.data.s);
            },function(res){
              alert(res.status);
            });
          }
        }
      });
    };
  </script>
</head>
<body>
  <input type="button" value="按鈕" @click="get()">
</body>
</html>

感興趣的朋友可以使用在線HTML/CSS/JavaScript代碼運(yùn)行工具http://tools.jb51.net/code/HtmlJsRun測(cè)試上述代碼運(yùn)行效果。

希望本文所述對(duì)大家vue.js程序設(shè)計(jì)有所幫助。

相關(guān)文章

  • Vue中的項(xiàng)目打包及部署全流程

    Vue中的項(xiàng)目打包及部署全流程

    這篇文章主要介紹了Vue中的項(xiàng)目打包及部署全流程,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。如有錯(cuò)誤或未考慮完全的地方,望不吝賜教
    2022-08-08
  • 詳解.vue文件解析的實(shí)現(xiàn)

    詳解.vue文件解析的實(shí)現(xiàn)

    這篇文章主要介紹了詳解.vue文件解析的實(shí)現(xiàn),小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,也給大家做個(gè)參考。一起跟隨小編過來看看吧
    2018-06-06
  • Vue中的異步組件函數(shù)實(shí)現(xiàn)代碼

    Vue中的異步組件函數(shù)實(shí)現(xiàn)代碼

    這篇文章主要介紹了Vue中的異步組件函數(shù)實(shí)現(xiàn)代碼,非常不錯(cuò),具有一定的參考借鑒價(jià)值,需要的朋友可以參考下
    2018-07-07
  • vue單行文本溢出會(huì)出現(xiàn)title提示自定義指令

    vue單行文本溢出會(huì)出現(xiàn)title提示自定義指令

    這篇文章主要為大家介紹了vue單行文本溢出會(huì)出現(xiàn)title提示自定義指令,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進(jìn)步,早日升職加薪
    2023-01-01
  • swiper/vue 獲取 swiper實(shí)例方法詳解

    swiper/vue 獲取 swiper實(shí)例方法詳解

    在網(wǎng)上搜了一下如何調(diào)用swiper實(shí)例,大部分都是通過 swiperRef = new Swiper(‘.swiper’, options) 這種方法初始化swiper,然后直接能用 swiperRef 實(shí)例,這篇文章主要介紹了swiper/vue 獲取 swiper實(shí)例方法詳解,需要的朋友可以參考下
    2023-12-12
  • Vue中iframe?結(jié)合?window.postMessage?實(shí)現(xiàn)跨域通信

    Vue中iframe?結(jié)合?window.postMessage?實(shí)現(xiàn)跨域通信

    window.postMessage()?方法可以安全地實(shí)現(xiàn)跨源通信,在一個(gè)項(xiàng)目的頁面中嵌入另一個(gè)項(xiàng)目的頁面,需要實(shí)現(xiàn)父子,子父頁面的通信,對(duì)Vue中iframe?結(jié)合?window.postMessage?實(shí)現(xiàn)跨域通信相關(guān)知識(shí)感興趣的朋友跟隨小編一起看看吧
    2022-12-12
  • vue實(shí)現(xiàn)簡(jiǎn)單的跑馬燈效果

    vue實(shí)現(xiàn)簡(jiǎn)單的跑馬燈效果

    這篇文章主要為大家詳細(xì)介紹了vue實(shí)現(xiàn)簡(jiǎn)單的跑馬燈效果,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下
    2021-10-10
  • vue3.0引入百度地圖并標(biāo)記點(diǎn)的實(shí)現(xiàn)代碼

    vue3.0引入百度地圖并標(biāo)記點(diǎn)的實(shí)現(xiàn)代碼

    這篇文章主要介紹了vue3.0引入百度地圖并標(biāo)記點(diǎn),本文通過實(shí)例代碼給大家介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或工作具有一定的參考借鑒價(jià)值,需要的朋友可以參考下
    2022-08-08
  • Vuejs第十一篇組件之slot內(nèi)容分發(fā)實(shí)例詳解

    Vuejs第十一篇組件之slot內(nèi)容分發(fā)實(shí)例詳解

    這篇文章主要介紹了Vuejs第十一篇之slot內(nèi)容分發(fā)組件詳解的相關(guān)資料
    2016-09-09
  • Vue3定義組件的四種方式

    Vue3定義組件的四種方式

    Vue 作為一款流行的前端框架,提供了多種方式來定義組件,包括單文件組件、渲染函數(shù)、、JSX/TSX 以及函數(shù)式組件、不同的方式適用于不同的場(chǎng)景,本文將對(duì)這四種方式進(jìn)行詳細(xì)對(duì)比,幫助你找到最適合自己項(xiàng)目的方案,需要的朋友可以參考下
    2025-03-03

最新評(píng)論

汝州市| 广州市| 丰城市| 萍乡市| 怀集县| 微山县| 常熟市| 天全县| 伽师县| 湟中县| 庆元县| 疏附县| 根河市| 化德县| 大洼县| 惠东县| 炉霍县| 荣昌县| 伊金霍洛旗| 溆浦县| 西盟| 屏山县| 吴江市| 子洲县| 民乐县| 旬邑县| 恩施市| 永和县| 雅江县| 政和县| 龙陵县| 日土县| 连南| 曲麻莱县| 介休市| 海宁市| 葵青区| 东阳市| 于都县| 蒙城县| 洛阳市|