<ruby id="bdb3f"></ruby>

    <p id="bdb3f"><cite id="bdb3f"></cite></p>

      <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
        <p id="bdb3f"><cite id="bdb3f"></cite></p>

          <pre id="bdb3f"></pre>
          <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

          <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
          <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

          <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                <ruby id="bdb3f"></ruby>

                ThinkChat2.0新版上線,更智能更精彩,支持會話、畫圖、視頻、閱讀、搜索等,送10W Token,即刻開啟你的AI之旅 廣告
                >[success] # 使用vue-resource 包進行異步 ## [vue-resource 實現 get, post, jsonp請求](https://github.com/pagekit/vue-resource) ~~~ 1.配置resource全局配置了,請求的數據接口 根域名 Vue.http.options.root = 'http://vue.studyit.io/'; 2.全局啟用 emulateJSON 選項Vue.http.options.emulateJSON = true;,就是當post 的時候不用在添加第三個參數 ~~~ * 獲取所有數據分析思路 ~~~ 1. 由于已經導入了 Vue-resource這個包,所以 ,可以直接通過 this.$http 來 發起數據請求 2. 根據接口API文檔,知道,獲取列表的時候,應該發起一個 get 請求 3. this.$http.get('url').then(function(result){}) 4. 當通過 then 指定回調函數之后,在回調函數中,可以拿到數據服務器返回的 result 5. 先判斷 result.status 是否等于0,如果等于0,就成功了,可以 把 result.message 賦值給 this.list ; 如果不等于0,可以彈框提醒,獲取數據失敗! ~~~ * 添加數據分析思路 ~~~ 1. 聽過查看 數據API接口,發現,要發送一個 Post 請求, this.$http.post 2. this.$http.post() 中接收三個參數: 2.1 第一個參數: 要請求的URL地址 2.2 第二個參數: 要提交給服務器的數據 ,要以對象形式提交給服務器 { name: this.name } 2.3 第三個參數: 是一個配置對象,要以哪種表單數據類型提交過去, { emulateJSON: true }, 以普通表單格式,將數據提交給服務器 application/x-www-form-urlencoded 3. 在 post 方法中,使用 .then 來設置成功的回調函數,如果想要拿到成功的結果,需要 result.body ~~~ >[danger] ##### 案例 ~~~ <script src="./lib/vue-2.4.0.js"></script> <!-- 注意:vue-resource 依賴于 Vue,所以先后順序要注意 --> <!-- this.$http.jsonp --> <script src="./lib/vue-resource-1.3.4.js"></script> </head> <body> <div id="app"> <input type="button" value="get請求" @click="getInfo"> <input type="button" value="post請求" @click="postInfo"> <input type="button" value="jsonp請求" @click="jsonpInfo"> </div> <script> // 創建 Vue 實例,得到 ViewModel var vm = new Vue({ el: '#app', data: {}, methods: { getInfo() { // 發起get請求 // 當發起get請求之后, 通過 .then 來設置成功的回調函數 this.$http.get('http://vue.studyit.io/api/getlunbo').then(function (result) { // 通過 result.body 拿到服務器返回的成功的數據 // console.log(result.body) }) }, postInfo() { // 發起 post 請求 application/x-wwww-form-urlencoded // 手動發起的 Post 請求,默認沒有表單格式,所以,有的服務器處理不了 // 通過 post 方法的第三個參數, { emulateJSON: true } 設置 提交的內容類型 為 普通表單數據格式 this.$http.post('http://vue.studyit.io/api/post', {}, { emulateJSON: true }).then(result => { console.log(result.body) }) }, jsonpInfo() { // 發起JSONP 請求 this.$http.jsonp('http://vue.studyit.io/api/jsonp').then(result => { console.log(result.body) }) } } }); </script> </body> </html> ~~~ >[danger] ##### 使用axios -- 基于promise 封裝的庫 ~~~ 1.去看文檔就能學會這個 ~~~
                  <ruby id="bdb3f"></ruby>

                  <p id="bdb3f"><cite id="bdb3f"></cite></p>

                    <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
                      <p id="bdb3f"><cite id="bdb3f"></cite></p>

                        <pre id="bdb3f"></pre>
                        <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

                        <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
                        <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

                        <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                              <ruby id="bdb3f"></ruby>

                              哎呀哎呀视频在线观看