我看过axios文档,但它说的只是
// Add a request interceptor
axios.interceptors.request.use(function (config) {
// Do something before request is sent
return config;
}, function (error) {
// Do something with request error
return Promise.reject(error);
});
// Add a response interceptor
axios.interceptors.response.use(function (response) {
// Do something with response data
return response;
}, function (error) {
// Do something with response error
return Promise.reject(error);
});
Run Code Online (Sandbox Code Playgroud)
同样,许多教程仅显示此代码,但是我很困惑它的用途,有人可以给我简单的示例进行操作。
我只是想在我的视图控制器中显示一个简单的渐变.此代码不起作用(视图保持白色).
import UIKit
import QuartzCore
class ViewController: UIViewController {
override func viewDidLoad() {
super.viewDidLoad()
let ly = CAGradientLayer()
ly.frame = view.bounds
ly.colors = [UIColor.orangeColor(), UIColor.blackColor()]
ly.locations = [0.0, 1.0]
println(view.bounds) // (0.0, 0.0, 320.0, 568.0)
view.layer.addSublayer(ly)
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
}
Run Code Online (Sandbox Code Playgroud)
有趣的是,如果我设置ly.backgroundColor
为橙色,视图将变为橙色.我们可以得出结论,图层有效地位于视图之上,但渐变无效.