我正在尝试使用Swift对REST API进行GET调用,并试图遵循大量的教程,但无法弄明白.或者因为我无法弄清楚如何将所有Obj-C翻译成Swift,或者因为这些方法的一半被弃用了.有谁知道如何进行调用,并解析返回的JSON数据?
我如何改变UINavigationBarSwift中的颜色?
网上的大多数事情都说要做以下事情:
[self.navigationController.navigationBar setTitleTextAttributes:@{NSForegroundColorAttributeName : [UIColor whiteColor]}];
Run Code Online (Sandbox Code Playgroud)
我翻译成了哪个
let titleDict: NSDictionary = ["NSForegroundColorAttributeName": UIColor.whiteColor()]
self.navigationController.navigationBartitleTextAttributes = titleDict
//self is referring to a UIViewController
Run Code Online (Sandbox Code Playgroud)
但它不起作用.我已经改变了背景和按钮颜色,但文本颜色没有改变.有任何想法吗?
现在我知道,当swift编译它只是创建一个NSDictionary,但NSDictionary和Swift词典有不同的语法.有没有办法(通过循环或其他东西)将NSDictionary转换为相同类型的快速字典<key, value>?
要么
有没有办法将其转换为Swift字典而不是NSDictionary?
let jsonDict = NSJSONSerialization.JSONObjectWithData(jsonData, options: nil, error: &error) as NSDictionary
Run Code Online (Sandbox Code Playgroud) 根据yarn v2 的yarn 安装,他们希望您使用npm install -g yarn. 所以我sudo npm install -g yarn在 Ubuntu 20.04 上运行。但我这样做后,它说找不到命令。
\xe2\x9d\xaf sudo npm install -g yarn\n\n> yarn@1.22.10 preinstall /usr/local/lib/node_modules/yarn\n> :; (node ./preinstall.js > /dev/null 2>&1 || true)\n\n\n\xe2\x9d\xaf yarn --version\nzsh: command not found: yarn\nRun Code Online (Sandbox Code Playgroud)\n 我有一个React前端,它使用jwt来验证Django后端.后端工作,并使用django视图连接正常,但当我尝试代理来自React的请求时,它给了我一个连接拒绝错误.
代理错误:无法将请求/ api/auth/token/gain /从localhost:3000代理到http:// localhost:8000(ECONNREFUSED).
连接到http:// localhost:8000/api/auth/token /获取/正常工作.并且使用Axios发送POST请求也能正常工作并返回令牌json.但是当我用节点代理它时,它不起作用.
在我的package.json身上:
"proxy": {
"/api/*": {
"target": "http://localhost:8000"
}
},
Run Code Online (Sandbox Code Playgroud)
编辑: 公共回购.如果安装了docker,则可以轻松运行.(使用1个图像和2个容器).克隆docker-compose build后再运行,然后docker-compose up.
Edit2:请求标题:
*General*
Request URL: http://localhost:3000/api/auth/token/obtain/
Request Method: POST
Status Code: 500 Internal Server Error
Remote Address: [::1]:3000
Referrer Policy: no-referrer-when-downgrade
*Response Headers*
HTTP/1.1 500 Internal Server Error
X-Powered-By: Express
Date: Mon, 30 Apr 2018 21:23:17 GMT
Connection: keep-alive
Transfer-Encoding: chunked
*Request Headers
POST /api/auth/token/obtain/ HTTP/1.1
Host: localhost:3000
Connection: …Run Code Online (Sandbox Code Playgroud) 之前,当我使用 create-react-app 制作应用程序时,我会有一个setupProxy.js文件来路由与此类似的 API 请求
const proxy = require('http-proxy-middleware');
module.exports = function(app) {
app.use('/api',
proxy({
target: 'http://localhost:8000',
changeOrigin: true,
})
);
};
Run Code Online (Sandbox Code Playgroud)
但这似乎不适用于 next.js。当我做同样的事情时,我会遇到各种错误。
谷歌搜索解决方案,很多人说使用某种自定义服务器。但是我将如何使用默认的 nextjs 开发服务器完成像上面这样的代理?(相当于我的 package.json 中的npm run devwhendev是next dev.
在 MUI v4 中,我的 JSS 类中有这样的内容:
paddingTop: theme.mixins.toolbar.minHeight + theme.spacing(1)
Run Code Online (Sandbox Code Playgroud)
然而,在 v5 中,theme.spacing()返回字符串而不是数字。所以上面的语句将 paddingTop 设置为568px,那么56+'8px'现在用间距进行数学计算的正确方法是什么?
如果我有AppBar,我怎么能这样做,所以一组图标加上徽标在左边,另一组图标在它的右边?
例如:
AppBar组件:
<AppBar
className={classNames(classes.appBar, {
[classes.appBarShift]: open,
[classes[`appBarShift-left`]]: open,
[classes[`appBarShift-right`]]: !tools,
})}
position='static'
>
<Toolbar className={classNames(classes.topBar)}>
<IconButton
color="inherit"
aria-label="open drawer"
onClick={this.handleDrawerToggle}
className={classNames(classes.menuButton)}
>
<MenuIcon />
</IconButton>
<Typography variant="title" color="inherit" noWrap>React App</Typography>
<IconButton
color="inherit"
aria-label="open tool drawer"
onClick={this.handleToolDrawerToggle}
className={classNames(classes.menuButton)}
>
<MenuIcon />
</IconButton>
</Toolbar>
</AppBar>
Run Code Online (Sandbox Code Playgroud) 我有一个网站设置与球童服务反应应用程序.但它的代理部分似乎并没有将请求转发给其他docker容器.它仍然显示我的反应页面example.com/api.
我的球童文件:
example.com {
gzip
root /app/build # directory of public pages # Single-page react app
proxy /staticfiles django:8000 {
transparent
}
proxy /api django:8000 {
transparent
}
}
Run Code Online (Sandbox Code Playgroud) 我正在尝试安装多个相同的宅基地框。每个用于不同的项目,彼此完全隔离。它们都不会同时运行,一次只能运行一个。
但是当我尝试运行时vagrant up,它告诉我一个名为“homestead-7”的盒子已经存在。我该如何重命名?
我在项目目录的 vagrantfile 中的任何地方都没有看到名称,也没有在项目 .vagrant 目录或我的主 .vagrant 目录中看到任何“boxes”文件夹。 vagrant global-status告诉我已经有 1 个 homestead-7 框用于已经在进行中的项目。
reactjs ×4
node.js ×3
swift ×3
javascript ×2
material-ui ×2
api ×1
axios ×1
caddy ×1
colors ×1
dictionary ×1
django ×1
docker ×1
hadoop-yarn ×1
homestead ×1
http ×1
ios ×1
laravel ×1
navigation ×1
next.js ×1
npm ×1
nsdictionary ×1
proxy ×1
rest ×1
text ×1
ubuntu ×1
vagrant ×1
virtualbox ×1