我试图从vue中的另一个方法内部调用一个方法。
我在控制台中得到的是一个未定义的,但我真正想要的是在getId函数中调用的id
总而言之,我要做的是使用addEvent函数来获取复选框事件,这样我就可以从中获取真或假,然后将其发送到saveCheckbox函数,并从saveCheckbox函数调用getId函数来获取特定复选框的ID。
我希望我能够正确地解释它。如果还不清楚,请告诉我。
这就是我的东西
<template>
<div class="card-body">
<table class="table">
<thead class="thead-dark">
<tr>
<th scope="col">Active</th>
<th scope="col">Title</th>
</tr>
</thead>
<tbody>
<tr v-for="(category, index) in categories" >
<td>
<input name="active" type="checkbox" v-model="category.active" @change="getId(category.id)" @click="addEvent">
</td>
<td>
{{ category.title }}
</td>
</tr>
</tbody>
</table>
</div>
</template>
<script>
export default {
props: [
'attributes'
],
data(){
return {
categories: this.attributes,
}
},
methods: {
getId(id){
console.log(id);
return id
},
saveCheckbox(event){
console.log(this.getId());
},
addEvent ({ type, target }) {
const event = {
type,
isCheckbox: target.type === 'checkbox',
target: {
value: target.value,
checked: target.checked
}
}
this.saveCheckbox(event.target.checked)
}
},
mounted() {
console.log('Component mounted.')
}
}
</script>发布于 2018-09-06 21:51:26
必须将参数(Id)传递给getId方法
发布于 2018-09-06 21:48:01
有了一个排序概述,您不会向该方法传递任何id,它会尝试返回该Id。也许,这就是没有定义的东西?
方法调用完成得很好。有了这个。前面的关键字
https://stackoverflow.com/questions/52205453
复制相似问题