laravel - 数据表ajax渲染中的按钮单击在Vue中不起作用
问题描述
我是 Vuejs 的新手。
我有一个用户表,它使用 Datatable 中的服务器端处理显示数据。我正在尝试添加一个单击事件,它将调用一个 vue 函数。但是点击功能根本不起作用。我尝试使用这些方法。但他们都没有工作。
v-on:click="函数名"
v-on:click="$emit('functionName')"
@click="函数名"
HTML 部分
<table class="table table-bordered data-table dataTable-load">
<thead class="thead-light">
<tr>
<th style="width: 80px;">No</th>
<th>Name</th>
<th>Email</th>
<th>Phone</th>
<th>Type</th>
<th>Created</th>
<th>Last Updated</th>
<th width="280px">Action</th>
</tr>
</thead>
<tbody></tbody>
</table>
<div>
<span v-html='data'></span>
</div>
脚本部分
var dt = $('.dataTable-load').DataTable({
processing: true,
serverSide: true,
ajax: {
url: "{{ url('user/getdata') }}",
type: "post",
data: {"_token": "{{ csrf_token() }}"}
},
columns: [
{name: 'id', data: 'id', },
{name: 'name', data: 'name'},
{name: 'email', data: 'email'},
{name: 'phone', data: 'phone'},
{name: 'usertype', data: 'usertype',
"render": function (data, type, row) {
if (row.usertype == 'M') {
return 'Manager';
} else {
return 'Staff';
}
}
},
{name: 'created_at', data: 'created_at'},
{name: 'updated_at', data: 'updated_at'},
{
title: 'msg',
"render": function (data, type, row) {
return '<button v-on:click="showModal" @click="showModal">the button</button>';
}
}
]
});
dt.on('order.dt search.dt', function () {
dt.column(0, {search: 'applied', order: 'applied'}).nodes().each(function (cell, i) {
cell.innerHTML = i + 1;
});
}).draw();
应用程序.js
const app = new Vue({
el: '#app',
data: {
data: '',
},
methods: {
showModal() {
this.data = 'Now click on me <a href=\'#\' @click.prevent=\'alert("yo")\'> here </a>';
},
},
});
请让我知道如何正确地做到这一点。提前谢谢你。
解决方案
推荐阅读
- apache-spark - 火花选项的文档
- python - 通过包含特定字符串从文件中删除行在python中不起作用
- reactjs - VSCode 键绑定导航到渲染方法
- flutter - Flutter:如何从 Uint8List 播放视频
- android - Android如何在api 24下以编程方式执行单击,长按和滑动操作(从左到右,从右到左,从下到上,从上到下)
- php - 上传文件名的PHP Laravel编码问题
- tensorflow - 带有 keras、tensorflow 的神经网络 InvalidArgumentError
- excel - 如何引用两个单独的范围?
- ansible - 仅更改文件的权限
- sql - 你能重写NVL函数吗?