nuxt.jshandsontable

How to implement handsontable into nuxt.js


Im trying to install handsontable on my project I use

npm install handsontable @handsontable/vue

Maybe I need to create a plugin? How Can I use handsontable in a existign nuxt project?


Solution

  • ok, I got success by this. Hope this helps you and save some time.

    1. Run npm install handsontable @handsontable/vue
    2. Create a file name vue-handsontable.js under plugins directory and put as following.
    const HotTable = !process.client ? null : require('@handsontable/vue').HotTable
    export default HotTable
    
    1. Open nuxt.config.js and append following.
      build: {
        vendor: ['handsontable'],
      },
      plugins: [
        { src: '~/plugins/vue-handsontable', ssr: false },
      ]
    
    1. Go to your template file and put lines like this.
    <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>
    

    Wish you best of luck.

    REV 1:

    The license key is obligatory since Handsontable 7.0.0 (released in March 2019).

    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'
    }