要通过thymeleaf语法向Vue方法传递参数,可以使用th:attr指令来设置自定义属性,并使用v-bind指令将自定义属性绑定到Vue方法中。\n\n在你的代码中,将th:attr指令用于td元素,并设置一个自定义属性来传递product.name的值,然后使用v-bind指令将该自定义属性绑定到getDialogData方法中。\n\n修改后的代码如下:\n\nhtml\n<td th:attr="data-product-name=${product.name}" v-on:click="getDialogData($event.target.getAttribute('data-product-name'))">\n <el-image class="ProductImage" th:src="${product.imgUrl}" :fit="'cover'"></el-image>\n <span class="ProductName" th:text="${product.name}">product-name</span>\n</td>\n\n\n在Vue的getDialogData方法中,通过$event.target.getAttribute('data-product-name')获取td元素的自定义属性值,然后传递给该方法作为参数。\n\n这样就可以实现在点击td时调用getDialogData方法并传递参数的功能。

Thymeleaf传参到Vue方法:在点击表格单元格时调用Vue方法

原文地址: http://www.cveoy.top/t/topic/qAiu 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录