按钮单击在DataTable Ajax渲染的Vue中不起作用

时间:2020-02-05 09:21:56

标签: laravel datatable vuejs2

我是Vuejs的新手。

我有一个用户表,该表使用数据表中的服务器端处理显示数据。我试图添加一个单击事件,该事件将调用vue函数。但是,单击功能根本不起作用。我尝试使用这些方法。但是它们都不起作用。

v-on:click =“ functionName”

v-on:click =“ $ emit('functionName')”

@ click =“ functionName”

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();

App.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>';
      },
   },
});

请让我知道如何正确执行操作。预先谢谢你。

0 个答案:

没有答案