我尝试在我的Nuxt.js项目中添加Tabulator。我已经完成了下一个组件:
<template>
<div ref="table"></div>
</template>
<script>
let Tabulator = require("tabulator-tables")
import 'tabulator-tables/dist/css/tabulator_simple.min.css'
let saveIcon = function(cell, formatterParams, onRendered) {
return "<img src='/icons/save.png'>";
}
export default {
data() {
return {
tabulator: null,
tableData: [
{
id: 1,
username: 'user',
email: 'email@email.ru',
activationCode:'1243412-123413-4134',
active: true,
admin: true,
user: true
}
],
}
},
watch: {
tableData: {
handler: function (newData) {
this.tabulator.replaceData(newData);
},
deep: true,
}
},
mounted(){
this.tabulator = new Tabulator(this.$refs.table, {
data: this.tableData,
reactiveData:true,
columns: [
{title:"#", field:"id", sorter:"number"},
{title:"Пользователь", field:"username", sorter:"string"},
{title:"Email", field:"email", sorter:"string"},
{title:"Код активации", field:"activationCode"},
{title:"Активный", field:"active", align:"center", formatter:"tickCross", editor:true},
{title:"Роли",
columns:[
{title:"Администратор", field:"admin", align:"center", formatter:"tickCross", editor:true},
{title:"Пользователь", field:"user", align:"center", formatter:"tickCross", editor:true},
],
},
{formatter:saveIcon, width: 30, align:"center", cellClick:function(e, cell){
this.$axios.$get('/admin/user')
.then((response) => {
console.log(result)
})
},
}
],
});
},
}
</script>我想在回调中使用来自Nuxt.js的'axios‘,但它不起作用。我不知道该怎么做。
据我所知,我将不能使用the中方法部分的函数。
发布于 2019-09-16 14:45:43
尝试使用箭头函数表达式。常规函数有他们自己的"this“。
{formatter:saveIcon, width: 30, align:"center", cellClick:(e, cell) => {
this.$axios.$get('/admin/user')
.then((response) => {
console.log(result)
})
},
}https://stackoverflow.com/questions/57941201
复制相似问题