我正在尝试在我使用的项目上安装handsontable
npm install handsontable @handsontable/vue
也许我需要创建一个插件? 如何在现有的 nuxt 项目中使用 Handsontable?
好吧,我就这样成功了。希望这对您有帮助并节省一些时间。
npm install handsontable @handsontable/vue
const HotTable = !process.client ? null : require('@handsontable/vue').HotTable
export default HotTable
build: {
vendor: ['handsontable'],
},
plugins: [
{ src: '~/plugins/vue-handsontable', ssr: false },
]
<template>
<HotTable :settings="settings" :data="data"></HotTable>
</template>
<script>
import HotTable from '~/plugins/vue-handsontable'
export default {
data: function() {
return {
settings: {
data: [
["", "Ford", "Volvo", "Toyota", "Honda"],
["2016", 10, 11, 12, 13],
["2017", 20, 11, 14, 13],
["2018", 30, 15, 12, 13]
],
colHeaders: true,
rowHeaders: true,
}
};
},
head: {
link: [
{ rel: 'stylesheet', type: 'text/css',
href: '/your/path/to/css/directory/handsontable.full.min.css' },
]
},
components: {
HotTable
}
}
</script>
祝你好运。
修订版 1:
自 Handsontable 7.0.0(2019 年 3 月发布)起,许可证密钥是强制性的。
settings: {
data: [
["", "Ford", "Volvo", "Toyota", "Honda"],
["2016", 10, 11, 12, 13],
["2017", 20, 11, 14, 13],
["2018", 30, 15, 12, 13]
],
rowHeaders: true,
colHeaders: true,
licenseKey: 'non-commercial-and-evaluation'
}
如果有人想知道如何使
registerAllModules()
工作,方法如下:
registerAllModules()
制作另一个插件,
在 /plugin
、handsontable-regis
/插件/handsontable-regis.js
const registerAllModules = !process.client ? null : require('handsontable/registry').registerAllModules
export default registerAllModules
/nuxt.config.js
lugins: [
{ src: '~/plugins/handsontable-regis', mode: 'client' },
]
activated
实时循环中的函数,如下所示<script>
import registerAllModules from '~/plugins/handsontable-regis'
import HotTable from '~/plugins/vue-handsontable'
export default {
data: function() {
return {
settings: {
data: [
["", "Ford", "Volvo", "Toyota", "Honda"],
["2016", 10, 11, 12, 13],
["2017", 20, 11, 14, 13],
["2018", 30, 15, 12, 13]
],
colHeaders: true,
rowHeaders: true,
licenseKey: 'non-commercial-and-evaluation'
}
};
},
head: {
link: [
{ rel: 'stylesheet', type: 'text/css',
href: '/your/path/to/css/directory/handsontable.full.min.css' },
]
},
components: {
HotTable
},
activated: {
registerAllModules
}
}
</script>
希望您会发现这很有用
如果想使用Handsontable.renderers.registerRenderer自定义渲染事件,在nuxt框架里import Handsontable from '~/plugins/handsontable'却失效是为什么呢