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
    })


  • 相关阅读:
    23-10 条件查询
    22-9 聚合函数
    关系抽取snowball
    关系抽取bootstrap
    NER
    GPT
    因果卷积 空洞卷积
    XL-NET
    transoformer-XL
    transoformer
  • 原文地址:https://www.cnblogs.com/congxueda/p/7081026.html
Copyright © 2011-2022 走看看