zoukankan      html  css  js  c++  java
  • vue vue-resource网络请求

    在使用get/post 网络请求,需要下载插件 "vue-resource"

    npm install vue-resource -s

    在路由要导入及注册

    import Vue from 'vue'
    import Router from 'vue-router'
    import VueResource from 'vue-resource'
    //import Hello from '@/components/Hello'
    
    Vue.use(Router)
    Vue.use(VueResource)
    // 基于全局Vue对象使用http
    Vue.http.get('/someUrl', [options]).then(successCallback, errorCallback);
    Vue.http.post('/someUrl', [body], [options]).then(successCallback, errorCallback);


    // 在一个Vue实例内使用$http
    this.$http.get('/someUrl', [options]).then(successCallback, errorCallback);
    this.$http.post('/someUrl', [body], [options]).then(successCallback, errorCallback);
    
    

    emulateHTTP的作用

    如果Web服务器无法处理PUT, PATCH和DELETE这种REST风格的请求,你可以启用enulateHTTP现象。启用该选项后,请求会以普通的POST方法发出,并且HTTP头信息的X-HTTP-Method-Override属性会设置为实际的HTTP方法。

    Vue.http.options.emulateHTTP = true;

    emulateJSON的作用

    如果Web服务器无法处理编码为application/json的请求,你可以启用emulateJSON选项。启用该选项后,请求会以application/x-www-form-urlencoded作为MIME type,就像普通的HTML表单一样。

    Vue.http.options.emulateJSON = true;

    GET请求
    this.$http.get("url", {params: objArg})
    .then(function(res){
    // success
    },function(){
    //error
    })

    POST请求
    this.$http.post('url', {params}, {emulateJSON: true})
    .then(function(res){
    //success
    },function(){
    //error
    })


  • 相关阅读:
    pyinstaller 将 python 代码打包成执行文件
    python excel 处理 xlrd & xlwt &xlutils
    服务器重启后 Nvidia 环境错误
    py 编译so
    cv 读取宽高和画框
    libreOffice doc 转pdf
    gunicorn 使用
    asp.net 跬步篇(4) EnableSessionState设置 引起的框架集加载问题
    驱驾ViewState利剑—压缩ViewState
    asp.net 开发 跬步篇〔3〕.net 邮件批量发送
  • 原文地址:https://www.cnblogs.com/congxueda/p/7081026.html
Copyright © 2011-2022 走看看