thymeleaf 與 vue 結合使用時,vue如何取模板里的值


<li th:each="grade : ${grades}" th:v-bind:class="|{current: gradeId==${grade.id}}|">
<a th:title="${grade.name}" href="javascript:void(0)"  th:id="${grade.id}"
  th:text="${grade.name}"  th:@click="|getCourses(${grade.id},subjectId,1)|"
  >二年級</a></li>

th:@click="|getCourses(${grade.id},subjectId,1)|"

@click為VUE里綁定的點擊事件,此時事件存在於thymeleaf的循環th:each下的元素,getCourses() 為vue里的方法屬於js,但是需要取到模板里產生的值<年級id>

此時可以用th:v-on:"| |" 或者th:@click="| | " 簡單來說就是將前端的方法當作字符串拼接起來,前面加th:就能解析${grade.id} 的值

th:v-bind:class="|{current: gradeId==${grade.id}}|"

同理,綁定class用於樣式也能如此


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM