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>
複製程式碼