[{"id":"b66f8b1e-cc14-4e89-9679-abd5687d283d","tags":[{"product":null,"links":null,"id":"9e117e35-984a-4c14-95ca-ef0ec7b9fb60","name":"\u65B0\u589E","color":"DarkGreen","productId":"098be112-50ec-44e4-b746-6bc8bf76af97"}]},{"id":"569bb90a-ea68-46c6-96f1-ab151c120714","tags":[{"product":null,"links":null,"id":"a2f84374-4a3f-4d22-96fd-765e9de495bf","name":"\u66F4\u65B0","color":"Coral","productId":"098be112-50ec-44e4-b746-6bc8bf76af97"}]},{"id":"5eb52f08-2d1a-4362-9ffc-4871bdc10f3f","tags":[{"product":null,"links":null,"id":"a2f84374-4a3f-4d22-96fd-765e9de495bf","name":"\u66F4\u65B0","color":"Coral","productId":"098be112-50ec-44e4-b746-6bc8bf76af97"}]},{"id":"341dd607-b97d-4d70-bde2-53acda6b6c95","tags":[{"product":null,"links":null,"id":"a2f84374-4a3f-4d22-96fd-765e9de495bf","name":"\u66F4\u65B0","color":"Coral","productId":"098be112-50ec-44e4-b746-6bc8bf76af97"}]},{"id":"05349273-414f-4208-9ea2-c4fc8f4ea2cb","tags":[{"product":null,"links":null,"id":"a2f84374-4a3f-4d22-96fd-765e9de495bf","name":"\u66F4\u65B0","color":"Coral","productId":"098be112-50ec-44e4-b746-6bc8bf76af97"}]},{"id":"86089f76-b778-4d52-821e-6f27de3df613","tags":[{"product":null,"links":null,"id":"9e117e35-984a-4c14-95ca-ef0ec7b9fb60","name":"\u65B0\u589E","color":"DarkGreen","productId":"098be112-50ec-44e4-b746-6bc8bf76af97"}]},{"id":"b81e4fd6-1fc5-43a0-a258-b6e16a5cbec6","tags":[{"product":null,"links":null,"id":"a2f84374-4a3f-4d22-96fd-765e9de495bf","name":"\u66F4\u65B0","color":"Coral","productId":"098be112-50ec-44e4-b746-6bc8bf76af97"}]},{"id":"8aa8ce31-43e4-438e-951f-241608435260","tags":[{"product":null,"links":null,"id":"a2f84374-4a3f-4d22-96fd-765e9de495bf","name":"\u66F4\u65B0","color":"Coral","productId":"098be112-50ec-44e4-b746-6bc8bf76af97"}]},{"id":"37343f41-6ec2-4c7e-b21d-2cc18d5ce1e0","tags":[{"product":null,"links":null,"id":"a2f84374-4a3f-4d22-96fd-765e9de495bf","name":"\u66F4\u65B0","color":"Coral","productId":"098be112-50ec-44e4-b746-6bc8bf76af97"}]},{"id":"5915e52f-64f8-4146-b8bd-81bead6324a3","tags":[{"product":null,"links":null,"id":"a2f84374-4a3f-4d22-96fd-765e9de495bf","name":"\u66F4\u65B0","color":"Coral","productId":"098be112-50ec-44e4-b746-6bc8bf76af97"}]},{"id":"836ba889-af9e-460d-a4cc-c24d922795f2","tags":[{"product":null,"links":null,"id":"a2f84374-4a3f-4d22-96fd-765e9de495bf","name":"\u66F4\u65B0","color":"Coral","productId":"098be112-50ec-44e4-b746-6bc8bf76af97"}]},{"id":"4ae14b06-bb68-4394-a210-a46b8f028346","tags":[{"product":null,"links":null,"id":"a2f84374-4a3f-4d22-96fd-765e9de495bf","name":"\u66F4\u65B0","color":"Coral","productId":"098be112-50ec-44e4-b746-6bc8bf76af97"}]},{"id":"d8f42066-e9dc-4411-bdcf-43b1a203370c","tags":[{"product":null,"links":null,"id":"9e117e35-984a-4c14-95ca-ef0ec7b9fb60","name":"\u65B0\u589E","color":"DarkGreen","productId":"098be112-50ec-44e4-b746-6bc8bf76af97"}]},{"id":"7ef86f16-b1a0-49f7-9592-612b9be02b25","tags":[{"product":null,"links":null,"id":"a2f84374-4a3f-4d22-96fd-765e9de495bf","name":"\u66F4\u65B0","color":"Coral","productId":"098be112-50ec-44e4-b746-6bc8bf76af97"}]},{"id":"b29c7775-a9a4-451e-a1b5-01d19ed5ca5e","tags":[{"product":null,"links":null,"id":"9e117e35-984a-4c14-95ca-ef0ec7b9fb60","name":"\u65B0\u589E","color":"DarkGreen","productId":"098be112-50ec-44e4-b746-6bc8bf76af97"}]},{"id":"e56f3989-8f81-46af-90fa-a4813eeb976f","tags":[{"product":null,"links":null,"id":"9e117e35-984a-4c14-95ca-ef0ec7b9fb60","name":"\u65B0\u589E","color":"DarkGreen","productId":"098be112-50ec-44e4-b746-6bc8bf76af97"}]},{"id":"2526c963-f170-45a8-923e-91b0712a9810","tags":[{"product":null,"links":null,"id":"9e117e35-984a-4c14-95ca-ef0ec7b9fb60","name":"\u65B0\u589E","color":"DarkGreen","productId":"098be112-50ec-44e4-b746-6bc8bf76af97"}]},{"id":"24575cf0-501a-44f9-8426-c40f8f4b5552","tags":[{"product":null,"links":null,"id":"a2f84374-4a3f-4d22-96fd-765e9de495bf","name":"\u66F4\u65B0","color":"Coral","productId":"098be112-50ec-44e4-b746-6bc8bf76af97"}]},{"id":"1a6f8d7f-acd6-42be-8c4f-f464c6218381","tags":[{"product":null,"links":null,"id":"a2f84374-4a3f-4d22-96fd-765e9de495bf","name":"\u66F4\u65B0","color":"Coral","productId":"098be112-50ec-44e4-b746-6bc8bf76af97"}]},{"id":"82b176fd-5cab-498c-909e-8fa7d29c38d8","tags":[{"product":null,"links":null,"id":"9e117e35-984a-4c14-95ca-ef0ec7b9fb60","name":"\u65B0\u589E","color":"DarkGreen","productId":"098be112-50ec-44e4-b746-6bc8bf76af97"}]},{"id":"1708b3a9-4f37-44a8-8f0e-f9a2d2e5d940","tags":[{"product":null,"links":null,"id":"9e117e35-984a-4c14-95ca-ef0ec7b9fb60","name":"\u65B0\u589E","color":"DarkGreen","productId":"098be112-50ec-44e4-b746-6bc8bf76af97"}]},{"id":"c9ac246e-29fb-4bc4-8231-8439795bb590","tags":[{"product":null,"links":null,"id":"9e117e35-984a-4c14-95ca-ef0ec7b9fb60","name":"\u65B0\u589E","color":"DarkGreen","productId":"098be112-50ec-44e4-b746-6bc8bf76af97"}]},{"id":"94f2a5c3-2539-436a-af75-23fbbd1a3957","tags":[{"product":null,"links":null,"id":"a2f84374-4a3f-4d22-96fd-765e9de495bf","name":"\u66F4\u65B0","color":"Coral","productId":"098be112-50ec-44e4-b746-6bc8bf76af97"}]},{"id":"d99594f4-2d40-4df4-9419-ba2ca6aa3f7f","tags":[{"product":null,"links":null,"id":"9e117e35-984a-4c14-95ca-ef0ec7b9fb60","name":"\u65B0\u589E","color":"DarkGreen","productId":"098be112-50ec-44e4-b746-6bc8bf76af97"}]},{"id":"fd66e72d-0f10-4f57-9807-6db26290ab2e","tags":[{"product":null,"links":null,"id":"a2f84374-4a3f-4d22-96fd-765e9de495bf","name":"\u66F4\u65B0","color":"Coral","productId":"098be112-50ec-44e4-b746-6bc8bf76af97"}]},{"id":"8f344863-503d-4bc3-a594-3815e7d55f5c","tags":[{"product":null,"links":null,"id":"9e117e35-984a-4c14-95ca-ef0ec7b9fb60","name":"\u65B0\u589E","color":"DarkGreen","productId":"098be112-50ec-44e4-b746-6bc8bf76af97"}]},{"id":"9be82601-de9d-4c18-948a-23ab6f4dd431","tags":[{"product":null,"links":null,"id":"9e117e35-984a-4c14-95ca-ef0ec7b9fb60","name":"\u65B0\u589E","color":"DarkGreen","productId":"098be112-50ec-44e4-b746-6bc8bf76af97"}]},{"id":"6495f3c0-b463-47e0-b08a-ca949672211e","tags":[{"product":null,"links":null,"id":"9e117e35-984a-4c14-95ca-ef0ec7b9fb60","name":"\u65B0\u589E","color":"DarkGreen","productId":"098be112-50ec-44e4-b746-6bc8bf76af97"}]},{"id":"b4bede08-3f08-4839-ba4a-abc7ac195bde","tags":[{"product":null,"links":null,"id":"9e117e35-984a-4c14-95ca-ef0ec7b9fb60","name":"\u65B0\u589E","color":"DarkGreen","productId":"098be112-50ec-44e4-b746-6bc8bf76af97"}]},{"id":"4afcdfc0-3ff5-4f2b-a223-f8fc042a5bbe","tags":[{"product":null,"links":null,"id":"9e117e35-984a-4c14-95ca-ef0ec7b9fb60","name":"\u65B0\u589E","color":"DarkGreen","productId":"098be112-50ec-44e4-b746-6bc8bf76af97"}]},{"id":"422062c4-fa40-4771-a86f-008efe6d86e5","tags":[{"product":null,"links":null,"id":"9e117e35-984a-4c14-95ca-ef0ec7b9fb60","name":"\u65B0\u589E","color":"DarkGreen","productId":"098be112-50ec-44e4-b746-6bc8bf76af97"}]},{"id":"d87e8013-86a7-4840-8d25-6f62e14eb4ac","tags":[{"product":null,"links":null,"id":"9e117e35-984a-4c14-95ca-ef0ec7b9fb60","name":"\u65B0\u589E","color":"DarkGreen","productId":"098be112-50ec-44e4-b746-6bc8bf76af97"}]},{"id":"a6acedfd-4043-4c64-a5d1-aec3326df9e7","tags":[{"product":null,"links":null,"id":"9e117e35-984a-4c14-95ca-ef0ec7b9fb60","name":"\u65B0\u589E","color":"DarkGreen","productId":"098be112-50ec-44e4-b746-6bc8bf76af97"}]},{"id":"dbdc0b24-06c4-48b9-8d6c-7455119dc773","tags":[{"product":null,"links":null,"id":"9e117e35-984a-4c14-95ca-ef0ec7b9fb60","name":"\u65B0\u589E","color":"DarkGreen","productId":"098be112-50ec-44e4-b746-6bc8bf76af97"}]},{"id":"a3856849-954a-4cfc-96a6-382e530d3638","tags":[{"product":null,"links":null,"id":"a2f84374-4a3f-4d22-96fd-765e9de495bf","name":"\u66F4\u65B0","color":"Coral","productId":"098be112-50ec-44e4-b746-6bc8bf76af97"}]},{"id":"4a39306b-ffa5-433d-80a3-28e41f929b72","tags":[{"product":null,"links":null,"id":"a2f84374-4a3f-4d22-96fd-765e9de495bf","name":"\u66F4\u65B0","color":"Coral","productId":"098be112-50ec-44e4-b746-6bc8bf76af97"}]}]
        
(Showing Draft Content)

在 NuxtJS 中使用 SpreadJS

SpreadJS 支持 NuxtJS,这是一个用于创建 Web 应用程序的 VueJS 框架。

NuxtJS 使开发变得简单、快速和有条理。NuxtJS 与 React.js 的框架 NextJS 非常相似。NuxtJS 的一些有用特性是文件夹结构、服务器端呈现、静态呈现和代码拆分。

有关详细信息,请参阅https://nuxtjs.org/docs/get-started/installation

在本教程中,我们构建了一个使用 SpreadJS 的Nuxt.js应用程序。

视图 2

创建 Nuxt.js 应用程序

创建 Nuxt.js 应用程序的最简单方法是使用 Create Next App 工具。

  1. 从命令提示符或终端运行以下命令以创建 Nuxt.js 项目。

    npx create-nuxt-app nuxt2WithSJS

    当终端提示配置信息时,选择需要的选项并回车确认。在终端安装并创建项目时稍等片刻。它会问你几个问题,以下是你可以使用的答案:

    Project language: JavaScript
    Project manager: Npm
    UI framework: None
    Template engine: HTML
    Nuxt.js modules: Axios
    Linting tools: ESLint
    Testing framework: None
    Rendering mode: Single Page App
    Deployment target: Static
    Development tools: jsconfig.json
    Continuous integration: None
    Version control system: Git
  2. 在终端中键入以下命令。

    cd nuxt2WithSJS
    npm run dev
  3. 使用浏览器打开以下链接。然后你会看到NextJS的欢迎页面。

    http://localhost:3000/

  4. 关闭当前终端。使用 Visual Studio Code 或 IDE 打开 nextjs-with-spreadjs 文件夹。

安装 SpreadJS

  1. 安装 SpreadJS 包。

    npm install --save @grapecity-software/spread-sheets-vue

    创建一个名为 components 的文件夹,如果它不存在于应用程序的根文件夹中。

  2. 创建一个 JavaScript XML 文件 SpreadSheet.vue 并将其添加到组件文件夹中,并在其中添加以下代码。

    <template>
    <div>
        <gc-spread-sheets :hostClass='hostClass'>
            <gc-worksheet :dataSource="dataTable">
                <gc-column :width="width" :dataField="'preferredFullName'"></gc-column>
                <gc-column :width="width" :dataField="'jobTitleName'"></gc-column>
                <gc-column :width="width" :dataField="'phoneNumber'"></gc-column>
                <gc-column :width="width" :dataField="'region'"></gc-column>
            </gc-worksheet>
        </gc-spread-sheets>
    </div>
    </template>
    
    <script>
    import '@grapecity-software/spread-sheets/styles/gc.spread.sheets.excel2016colorful.css'
    import '@grapecity-software/spread-sheets-vue'
    
    export default {
        data() {
            return {
                hostClass: 'spread-host',
                width: 100
            }
        },
        computed: {
            dataTable() {
                return [{
                        "jobTitleName": "Developer",
                        "preferredFullName": "Romin Irani",
                        "region": "CA",
                        "phoneNumber": "408-1234567"
                    },
                    {
                        "jobTitleName": "Developer",
                        "preferredFullName": "Neil Irani",
                        "region": "CA",
                        "phoneNumber": "408-1111111"
                    },
                    {
                        "jobTitleName": "Program Directory",
                        "preferredFullName": "Tom Hanks",
                        "region": "CA",
                        "phoneNumber": "408-2222222"
                    }
                ];
            }
        }
    }
    </script>
    
    <style scoped>
    .spread-host {
        width: 600px;
        height: 600px;
    }
    </style>
  3. 更改索引文件内容。用以下代码替换 pages\index.tsx 文件的默认内容。

    <template>
    <div>
        <h1>
            Adding Spreadsheets to a Jamstack Application
        </h1>
        <p>
            Nuxt.JS v2 + SpreadJS demo
        </p>
        <SpreadSheet />
    </div>
    </template>

运行和测试应用程序

您可以使用 npm run dev 命令运行该应用程序。默认情况下,该项目在 http://localhost:3000/ 运行。

视图 3

创建 Nuxt.js 应用程序

创建 Nuxt.js 应用程序的最简单方法是使用 Create Next App 工具。

  1. 从命令提示符或终端运行以下命令以创建 Nuxt.js 项目。

    npx nuxi init nuxt3WithSJS
  2. 在终端中键入以下命令。

    cd nuxt3WithSJS
    npm install
    npm run dev
  3. 使用浏览器打开以下链接。然后你会看到NextJS的欢迎页面。

    http://localhost:3000/

  4. 关闭当前终端。使用 Visual Studio Code 或 IDE 打开 nextjs-with-spreadjs 文件夹。

安装 SpreadJS

  1. 安装 SpreadJS 包。

    npm install --save @grapecity-software/spread-sheets-vue

    创建一个名为 components 的文件夹,如果它不存在于应用程序的根文件夹中。

  2. 创建一个 JavaScript XML 文件 SpreadSheet.vue 并将其添加到组件文件夹中,并在其中添加以下代码。

    <template>
    <div>
        <gc-spread-sheets :hostClass='hostClass'>
            <gc-worksheet :dataSource="dataTable">
                <gc-column :width="width" :dataField="'preferredFullName'"></gc-column>
                <gc-column :width="width" :dataField="'jobTitleName'"></gc-column>
                <gc-column :width="width" :dataField="'phoneNumber'"></gc-column>
                <gc-column :width="width" :dataField="'region'"></gc-column>
            </gc-worksheet>
        </gc-spread-sheets>
    </div>
    </template>
    
    <script>
    import '@grapecity-software/spread-sheets/styles/gc.spread.sheets.excel2016colorful.css'
    import {
        GcSpreadSheets,
        GcWorksheet,
        GcColumn
    } from '@grapecity-software/spread-sheets-vue'
    
    export default {
        components: {
            GcSpreadSheets, GcWorksheet, GcColumn
        },
        data() {
            return {
                hostClass: 'spread-host',
                width: 100
            }
        },
        computed: {
            dataTable() {
                return [{
                        "jobTitleName": "Developer",
                        "preferredFullName": "Romin Irani",
                        "region": "CA",
                        "phoneNumber": "408-1234567"
                    },
                    {
                        "jobTitleName": "Developer",
                        "preferredFullName": "Neil Irani",
                        "region": "CA",
                        "phoneNumber": "408-1111111"
                    },
                    {
                        "jobTitleName": "Program Directory",
                        "preferredFullName": "Tom Hanks",
                        "region": "CA",
                        "phoneNumber": "408-2222222"
                    }
                ];
            }
        }
    }
    </script>
    
    <style scoped>
    .spread-host {
        width: 600px;
        height: 600px;
    }
    </style>
  3. 用以下代码替换 app.vue 文件的默认内容。

    <template>
    <div>
        <h1>
            Adding Spreadsheets to a Jamstack Application
        </h1>
        <p>
            Nuxt.JS v3 + SpreadJS demo
        </p>
        <SpreadSheet />
    </div>
    </template>
  4. 更改 nuxt.config.ts 文件,如下所示:

    // https://nuxt.com/docs/api/configuration/nuxt-config
    export default defineNuxtConfig({
        ssr: false,
        components: true
    })

运行和测试应用程序

您可以使用 npm run dev 命令运行该应用程序。默认情况下,该项目在 http://localhost:3000/ 运行。