如何将 handsontable 实现到 nuxt.js

How to implement handsontable into nuxt.js

我正在尝试在我使用的项目中安装 handsontable

npm install handsontable @handsontable/vue

也许我需要创建一个插件? 如何在现有的 nuxt 项目中使用 handsontable?

ok,我就这样成功了。希望这对您有所帮助并节省一些时间。

  1. 运行 npm install handsontable @handsontable/vue
  2. plugins目录下新建一个文件名vue-handsontable.js,如下所示
const HotTable = !process.client ? null : require('@handsontable/vue').HotTable
export default HotTable
  1. 打开 nuxt.config.js 并添加以下内容。
  build: {
    vendor: ['handsontable'],
  },
  plugins: [
    { src: '~/plugins/vue-handsontable', ssr: false },
  ]
  1. 转到您的模板文件并输入这样的行。
<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'
}