Leaf创建
2018-10-27 本文已影响0人
小熊翻译App
- 在
.package
文件添加依赖:
.package(url: "https://github.com/vapor/leaf.git", from: "3.0.0-rc"),
如下图:

-
终端切换到项目所在的文件夹目录:如下图
image.png
-
执行
vapor update
如下图:
image.png
-
根据提示第一个输入选择:
y
5.在configure
设置写入以下图示代码:
try services.register(LeafProvider())
config.prefer(LeafRenderer.self, for: ViewRenderer.self)

- 创建
Resources
->Views
文件夹
1).
image.png
2).
image.png
- 在Resources
->
Views创建一个NewFile:
index.leaf`文件
如下图:
image.png

- 在
index.leaf
中写入以下代码并转换成html文件,如下图:
<html>
<head></head>
<body>
<h1>Welcome to Side Swift Using Vapor</h1>
</body>
</html>


- 在
routes
文件写入以下代码:
router.get("hello") { req in
return try req.view().render("index")
}

-
command + R
运行并在浏览器打开:
http://localhost:8080/hello
效果如下:
image.png