美文网首页
Leaf创建

Leaf创建

作者: 小熊翻译App | 来源:发表于2018-10-27 16:28 被阅读0次
  1. .package文件添加依赖:
.package(url: "https://github.com/vapor/leaf.git", from: "3.0.0-rc"),

如下图:


image.png
  1. 终端切换到项目所在的文件夹目录:如下图


    image.png
  2. 执行 vapor update
    如下图:

    image.png
  3. 根据提示第一个输入选择:y

5.在configure设置写入以下图示代码:

try services.register(LeafProvider())

config.prefer(LeafRenderer.self, for: ViewRenderer.self)
image.png
  1. 创建Resources->Views文件夹
    1).
    image.png
    2).
    image.png
  1. 在Resources->Views创建一个NewFile:index.leaf`文件
    如下图:
    image.png
image.png
  1. index.leaf中写入以下代码并转换成html文件,如下图:
<html>

<head></head>

<body>
<h1>Welcome to Side Swift Using Vapor</h1>
</body>

</html>
image.png image.png
  1. routes文件写入以下代码:
router.get("hello") { req in
        return try req.view().render("index")
    }
image.png
  1. command + R 运行并在浏览器打开:
    http://localhost:8080/hello
    效果如下:
    image.png

相关文章

网友评论

      本文标题:Leaf创建

      本文链接:https://www.haomeiwen.com/subject/zwedtqtx.html