【发布时间】:2020-02-20 10:47:57
【问题描述】:
这是我店里的。
getters: {
getFormattedUsers (state) {
state.users.forEach(v => {
v.fullname = `${capitalize(v.fname)} ${capitalize(v.lname)}`
v.created_from_now = moment(v.created_at).fromNow()
v.approve_button = `<button @click="openApproveModal" class="btn btn-primary">Approve</button>`
})
return state.users
}
}
现在在我的组件中(挂载的属性),
async mounted () {
await this.initializeUsers()
$('#dataTable').DataTable({
data: this.getFormattedUsers(),
columns: [
{data: 'fullname'},
{data: 'username'},
{data: 'is_approved'},
{data: 'created_from_now'},
{data: 'approve_button'}
]
})
}
假设当您点击批准按钮
methods: {
openApproveModal (id) {
console.log('Approved!')
}
}
但事实证明,它什么也没记录。该函数根本没有被调用。
此外,这就是我的组件表的样子:
<table class="table table-bordered" id="dataTable">
<thead>
<tr>
<th>Name</th>
<th>Username</th>
<th>Status</th>
<th>Registration Date</th>
<th width="5">Action</th>
</tr>
</thead>
</table>
【问题讨论】:
-
所以您说的是在调用 getter 时您正在单击 vuex getter 中的按钮。对吗?
-
是的,@Yahiya
标签: javascript vue.js datatable vuex