【问题标题】:Requests with Aurelia Framework使用 Aurelia 框架的请求
【发布时间】:2016-11-01 00:35:07
【问题描述】:

有一个文件(可能是 main.js),我可以在其中为我的所有请求设置 baseUrl?

我从 Aurelia 开始,如果是一个愚蠢的问题,很抱歉。

【问题讨论】:

标签: javascript aurelia


【解决方案1】:

在 HttpClient 上使用 withBaseUrl configuration option

这是来自 App 类中 http://www.elanderson.net/2015/09/aurelia-with-asp-net-5-and-web-api/ 的示例。

import {HttpClient} from 'jspm_packages/github/aurelia/fetch-client@0.1.2/aurelia-fetch-client.js';
import 'fetch';

@inject(HttpClient)
export class App{ 
    constructor(http){
        http.configure(config => {
            config
              .useStandardConfiguration()
              .withBaseUrl('http://localhost:14830/api/');
        });

        this.http = http;
    }
}

【讨论】:

    猜你喜欢
    • 2019-03-13
    • 2013-06-12
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-04-04
    • 1970-01-01
    • 2016-04-07
    • 1970-01-01
    相关资源
    最近更新 更多