当前位置: 首页 > news >正文

vue2使用univerjs

1、univerjs

Univer 提供了一个全面的企业级文档与数据协同的解决方案,支持电子表格、文本文档和演示幻灯片三大核心文档类型。通过灵活的 API 和插件机制,开发者可以在 Univer 的基础上进行个性化功能的定制和扩展,以适应不同用户在不同场景下的特定需求。

2、开发配置

node版本

v16.20.2

package.json

 "dependencies": {"@univerjs/core": "0.2.4","@univerjs/design": "0.2.4","@univerjs/docs": "0.2.4","@univerjs/docs-ui": "0.2.4","@univerjs/engine-formula": "0.2.4","@univerjs/engine-render": "0.2.4","@univerjs/facade": "^0.2.4","@univerjs/network": "0.2.4","@univerjs/rpc": "0.2.4","@univerjs/sheets": "0.2.4","@univerjs/sheets-formula": "0.2.4","@univerjs/sheets-numfmt": "0.2.4","@univerjs/sheets-ui": "0.2.4","@univerjs/ui": "0.2.4",
}"devDependencies": {"@univerjs/webpack-plugin": "0.4.3",}

vue.config.js

const { UniverPlugin } = require('@univerjs/webpack-plugin')
module.exports = {configureWebpack: {plugins: [new UniverPlugin(),]}
}

3、vue代码

封装成组件UniverSheet.vue

<template><div ref="container"class="univer-container"></div>
</template><script>
import { Univer, UniverInstanceType, LocaleType } from '@univerjs/core'
import { defaultTheme } from '@univerjs/design'
import { UniverDocsPlugin } from '@univerjs/docs'
import { UniverDocsUIPlugin } from '@univerjs/docs-ui'
import { UniverFormulaEnginePlugin } from '@univerjs/engine-formula'
import { UniverRenderEnginePlugin } from '@univerjs/engine-render'
import { UniverSheetsPlugin } from '@univerjs/sheets'
import { UniverSheetsFormulaPlugin } from '@univerjs/sheets-formula'
import { UniverSheetsUIPlugin } from '@univerjs/sheets-ui'
import { UniverUIPlugin } from '@univerjs/ui'
import { FUniver  } from '@univerjs/facade'
import { zhCN, enUS } from 'univer:locales'
import '@univerjs/sheets-ui/lib/index.css'
export default {name: 'UniverSheet',props: {data: {value: Object,default: () => ({})}},watch: {data: {handler(val) {this.destroyUniver()this.init(val)},immediate: true}},data() {return {univer: null,workbook: null,univerAPI: null}},mounted() {this.init(this.data)},methods: {init(data = {}) {const univer = new Univer({theme: defaultTheme,locale: LocaleType.ZH_CN,locales: {[LocaleType.ZH_CN]: zhCN,[LocaleType.EN_US]: enUS}})this.univer = univeruniver.registerPlugin(UniverRenderEnginePlugin)univer.registerPlugin(UniverFormulaEnginePlugin)univer.registerPlugin(UniverUIPlugin, {container: this.$refs.container})univer.registerPlugin(UniverDocsPlugin, {hasScroll: false})univer.registerPlugin(UniverDocsUIPlugin)univer.registerPlugin(UniverSheetsPlugin)univer.registerPlugin(UniverSheetsUIPlugin)univer.registerPlugin(UniverSheetsFormulaPlugin)this.workbook = univer.createUnit(UniverInstanceType.UNIVER_SHEET, data)this.univerAPI = FUniver.newAPI(univer)},destroyUniver() {this.univer?.dispose()this.univer = nullthis.workbook = null},getData() {if (!this.workbook) {throw new Error('未初始化')}return this.workbook.save()}}
}
</script>
<style scoped>
.univer-container {width: 100%;height: 100%;overflow: hidden;
}
:global(.univer-menubar) {display: none;
}
</style>

引用组件

<template><div style=" height: 100%;width: 100%;"><button @click="getData">获取数据</button><UniverSheet id="sheet"ref="univerRef":data="data" /></div>
</template><script>
import UniverSheet from './UniverSheet.vue'
export default {components: {UniverSheet,},data() {return {data: {},}},methods: {getData() {const result = this.$refs.univerRef?.getData()console.log(JSON.stringify(result, null, 2))},},
}
</script><style lang="less" scoped>
</style>

效果图

在这里插入图片描述

http://www.lryc.cn/news/407680.html

相关文章:

  • VUE3 el-table-column header新增必填*
  • 条件概率和贝叶斯公式
  • Kali中docker与docker-compose的配置
  • C++ | Leetcode C++题解之第283题移动零
  • Exponential Moving Average (EMA) in Stable Diffusion
  • 017、Vue动态tag标签
  • RocketMQ 架构概览
  • 优化医疗数据管理:Kettle ETL 数据采集方案详解
  • spring-from表单
  • 【.NET】asp.net core 程序重启容器后redis无法连接,连接超时
  • 【vue前端项目实战案例】Vue3仿今日头条App
  • 常见的文心一言的指令
  • 数字货币交易接口实现(含源代码)
  • c++函数以及函数分文件编写
  • 【JVM基础06】——组成-直接内存详解
  • 学术研讨 | 区块链与隐私计算领域专用硬件研讨会顺利召开
  • AngularJS API 深入解析
  • 过某开源滑动验证码
  • 一文解决 | Linux(Ubuntn)系统安装 | 硬盘挂载 | 用户创建 | 生信分析配置
  • Matlab M_map工具箱绘制Interrupted Mollweide Projection
  • Python 变量与基本数据类型
  • Pytorch深度学习实践(5)逻辑回归
  • 认识漏洞-GitLab 远程命令执行漏洞、致远OA-ajax.do未授权任意文件上传漏洞
  • vue实现电子签名、图片合成、及预览功能
  • 【flink】之如何消费kafka数据?
  • 科研绘图系列:R语言山脊图(Ridgeline Chart)
  • Boost搜索引擎:如何建立 用户搜索内容 与 网页文件内容 之间的关系
  • 【QT】QT 窗口(菜单栏、工具栏、状态栏、浮动窗口、对话框)
  • Golang | Leetcode Golang题解之第283题移动零
  • ubuntu22.04 安装 NVIDIA 驱动以及CUDA