Dependency

<dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-web</artifactId>
    <version>1.5.4.RELEASE</version>
</dependency>

<dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-thymeleaf</artifactId>
    <version>1.5.4.RELEASE</version>
</dependency>

<dependency>
    <groupId>net.sourceforge.nekohtml</groupId>
    <artifactId>nekohtml</artifactId>
    <version>1.9.22</version>
</dependency>

Controller

@Controller
public class IndexController {

    @RequestMapping("vue-thymeleaf")
    public String vueThymeleaf(Model model) {
        model.addAttribute("items", Lists.newArrayList("aa", "bb", "cc"));
        return "vue-thymeleaf"; //对应文件:resources/templates/vue-thymeleaf.html
    }
}

html

<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <script src="lib/vue-v2.5.2.js"></script>
</head>
<body>
<div id="app-6">
    <p v-for="item in items">{{ item }}</p>
</div>
<script th:inline="javascript">
    var items = /*[[${items}]]*/ [];
    new Vue({
        el: '#app-6',
        data: {
            items: items
        }
    });
</script>
</body>
</html>
Logo

前往低代码交流专区

更多推荐