无法使用 Tabulator 在 VueJs 中获取数据的问题
Issue of unable to fetch data in VueJs using Tabulator
我已经在 VueJs 中使用制表符设置了一个 table。我遵循了 VueJs 中制表符设置的说明,来自:http://tabulator.info/docs/4.1/frameworks#vue 在这里,我试图从 table 中获取数据。由于某种原因,我无法获取。我看到我的 table 但没有数据。这是我的代码:
<template>
<div ref="table"> </div>
</template>
<script>
var Tabulator = require('tabulator-tables')
export default {
name: 'Location',
data: function () {
return {
tabulator: null, // variable to hold your table
location: [] // data for table to display
}
},
watch: {
// update table if data changes
location: {
handler: function (newData) {
this.tabulator.replaceData(newData)
},
deep: true
}
},
created: function () {
console.log('Location', this.$refs)
this.initialize()
},
mounted () {
// instantiate Tabulator when element is mounted
this.tabulator = new Tabulator(this.$refs.table, {
data: this.location, // link data to table
addRowPos:"bottom",
columns: [
{title: 'Code', field: 'code', sorter: 'string',width: 100, editor: 'input' , validator: "required"},
{title: 'Name', field: 'name', sorter: 'string', width: 200 , validator: "required",editor:"autocomplete", editorParams:{allowEmpty:true, showListOnEmpty:true, values:true}},
{title: 'Under', field: 'under', sorter: 'string', width: 200, editor: 'input' , validator: "required"},
{title: 'Status', field: 'status', sorter: 'string',width: 100, editor: 'input' , validator: "required"},
{title: 'Description', field: 'description', sorter: 'string', width: 200, editor: 'input' , validator: "required"},
{title: 'Depth', field: 'depth', sorter: 'string', width: 100, editor: 'input' , validator: "required"}
]
})
//Reset table contents on "Reset the table" button click
$("reset").click(function(){
table.setData(tabledata);
})
},
}
</script>
<template>
<div ref="table">
</div>
</template>
<script>
var Tabulator = require('tabulator-tables')
export default {
name: 'Location',
data: function () {
return {
tabulator: null, // variable to hold your table
location: [] // data for table to display
}
},
watch: {
// update table if data changes
location: {
handler: function (newData) {
this.tabulator.replaceData(newData)
},
deep: true
}
},
created: function () {
console.log('Location', this.$refs)
this.initialize()
},
methods: {
initialize () {
axios.get('/api/location')
.then(response => this.location = response.data.location)
}
},
mounted () {
// instantiate Tabulator when element is mounted
this.tabulator = new Tabulator(this.$refs.table, {
data: this.location,
layout:"fitDataStretch",
movableColumns:true,
addRowPos:"bottom",
// link data to table
columns: [
{title: 'Code', field: 'code', sorter: 'string',width: 100, editor: 'input' , validator: "required"},
{title: 'Name', field: 'name', sorter: 'string', width: 200 , validator: "required",editor:"autocomplete", editorParams:{allowEmpty:true, showListOnEmpty:true, values:true}},
{title: 'Under', field: 'under', sorter: 'string', width: 200, editor: 'input' , validator: "required"},
{title: 'Status', field: 'status', sorter: 'string',width: 100, editor: 'input' , validator: "required"},
{title: 'Description', field: 'description', sorter: 'string', width: 200, editor: 'input' , validator: "required"},
{title: 'Depth', field: 'depth', sorter: 'string', width: 100, editor: 'input' , validator: "required"}
]
});
},
}
</script>
<style scoped>
</style>
我已经在 VueJs 中使用制表符设置了一个 table。我遵循了 VueJs 中制表符设置的说明,来自:http://tabulator.info/docs/4.1/frameworks#vue 在这里,我试图从 table 中获取数据。由于某种原因,我无法获取。我看到我的 table 但没有数据。这是我的代码:
<template>
<div ref="table"> </div>
</template>
<script>
var Tabulator = require('tabulator-tables')
export default {
name: 'Location',
data: function () {
return {
tabulator: null, // variable to hold your table
location: [] // data for table to display
}
},
watch: {
// update table if data changes
location: {
handler: function (newData) {
this.tabulator.replaceData(newData)
},
deep: true
}
},
created: function () {
console.log('Location', this.$refs)
this.initialize()
},
mounted () {
// instantiate Tabulator when element is mounted
this.tabulator = new Tabulator(this.$refs.table, {
data: this.location, // link data to table
addRowPos:"bottom",
columns: [
{title: 'Code', field: 'code', sorter: 'string',width: 100, editor: 'input' , validator: "required"},
{title: 'Name', field: 'name', sorter: 'string', width: 200 , validator: "required",editor:"autocomplete", editorParams:{allowEmpty:true, showListOnEmpty:true, values:true}},
{title: 'Under', field: 'under', sorter: 'string', width: 200, editor: 'input' , validator: "required"},
{title: 'Status', field: 'status', sorter: 'string',width: 100, editor: 'input' , validator: "required"},
{title: 'Description', field: 'description', sorter: 'string', width: 200, editor: 'input' , validator: "required"},
{title: 'Depth', field: 'depth', sorter: 'string', width: 100, editor: 'input' , validator: "required"}
]
})
//Reset table contents on "Reset the table" button click
$("reset").click(function(){
table.setData(tabledata);
})
},
}
</script>
<template>
<div ref="table">
</div>
</template>
<script>
var Tabulator = require('tabulator-tables')
export default {
name: 'Location',
data: function () {
return {
tabulator: null, // variable to hold your table
location: [] // data for table to display
}
},
watch: {
// update table if data changes
location: {
handler: function (newData) {
this.tabulator.replaceData(newData)
},
deep: true
}
},
created: function () {
console.log('Location', this.$refs)
this.initialize()
},
methods: {
initialize () {
axios.get('/api/location')
.then(response => this.location = response.data.location)
}
},
mounted () {
// instantiate Tabulator when element is mounted
this.tabulator = new Tabulator(this.$refs.table, {
data: this.location,
layout:"fitDataStretch",
movableColumns:true,
addRowPos:"bottom",
// link data to table
columns: [
{title: 'Code', field: 'code', sorter: 'string',width: 100, editor: 'input' , validator: "required"},
{title: 'Name', field: 'name', sorter: 'string', width: 200 , validator: "required",editor:"autocomplete", editorParams:{allowEmpty:true, showListOnEmpty:true, values:true}},
{title: 'Under', field: 'under', sorter: 'string', width: 200, editor: 'input' , validator: "required"},
{title: 'Status', field: 'status', sorter: 'string',width: 100, editor: 'input' , validator: "required"},
{title: 'Description', field: 'description', sorter: 'string', width: 200, editor: 'input' , validator: "required"},
{title: 'Depth', field: 'depth', sorter: 'string', width: 100, editor: 'input' , validator: "required"}
]
});
},
}
</script>
<style scoped>
</style>