这是我的前端代码:div class=Products table tr theach=product productStat $indexProducts thif=$productStatindex 3 == 0 td click=getDialogData$productna
要将Thymeleaf获取到的数据传递给Vue应用中的方法,你可以使用v-bind指令将数据绑定到HTML元素上,然后在点击事件中访问绑定的数据。以下是你可以尝试的修改:
- 在
td元素上使用v-bind将product.name绑定到一个自定义属性上,例如data-product-name:
<td @click="getDialogData" v-bind:data-product-name="product.name">
- 修改
getDialogData方法,使其能够访问绑定的数据。你可以使用event.target.getAttribute('data-product-name')来获取绑定的数据:
getDialogData(event){
const _this = this
_this.dialogVisible = true
const name = event.target.getAttribute('data-product-name')
console.log("name: "+name)
axios({
url: "http://localhost:8080/index/getProduct",
method: "get",
params: {
name: name
}
}).then(function (resp){
console.log(resp.data)
})
},
这样,当你点击td元素时,getDialogData方法就会被调用,并且可以获取到绑定的product.name作为参数
原文地址: https://www.cveoy.top/t/topic/iUlM 著作权归作者所有。请勿转载和采集!