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

Vue使用epubjs电子书

 npmjs: https://www.npmjs.com/package/epubjs 

在线电子书转换器

安装:

npm i epubjs

简单封装: 

 src/hooks/

import Epub from "epubjs";
import type { Book, Rendition } from 'epubjs'
import type { BookOptions } from 'epubjs/types/book'
import type { RenditionOptions } from 'epubjs/types/rendition'export function useEpub() {let book: Booklet rendition: Renditionfunction createBook(urlOrData?: string | ArrayBuffer, options?: BookOptions) {if(!urlOrData) {book = Epub(options)} else {book = Epub(urlOrData, options)}return book}function render(element: Element | string, options?: RenditionOptions) {if(!book) returnif(typeof element === 'string') {rendition = book.renderTo(element, options)} else {rendition = book.renderTo(element, options)}return rendition}function display() {if(!rendition) returnreturn rendition.display()}function getBook() {return book}function getRendition() {return rendition}return { createBook, render, display, getBook, getRendition }
}

使用: 

<template><div class="main"><div id="epub"></div><div class="btn"><button @click="pre">pre</button><button @click="next">next</button></div></div>
</template>
<script setup lang="ts">
import { useEpub } from '../hooks'
import { onMounted } from 'vue'const { createBook, render, display, getRendition } = useEpub()onMounted(() => {createBook('static/example.epub')render('epub', { width: '100%', height: '100%' })display()
})// 上一页
const pre = async () => {await getRendition().prev()
}// 下一页
const next = async () => {await getRendition().next()
}
</script>
<style scoped>
.main {width: 100%;height: 100%;display: flex;flex-direction: column;justify-content: center;align-items: center;
}.main > #epub {width: 500px;height: 500px;border: 1px dashed red;box-sizing: border-box;
}
.main .btn {display: flex;justify-content: space-between;margin-top: 5px;
}
.main .btn button {padding: 7px 15px;margin-left: 20px;
}
</style>

这个示例电子书地址:https://example-files.online-convert.com/ebook/epub/example.epub 

直接下载下来,放在public/static下。

这篇只是简单写一下使用,还没有正式用到

更多可以参考另一位博主的文章:https://blog.csdn.net/qq_42484429/article/details/93158645?ops_request_misc=&request_id=&biz_id=102&utm_term=vue%E4%BD%BF%E7%94%A8epubjs&utm_medium=distribute.pc_search_result.none-task-blog-2~all~sobaiduweb~default-2-93158645.142^v96^pc_search_result_base9&spm=1018.2226.3001.4187

写的相对更详细一些,也可以看着源码调用对应方法来实现对应功能。

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

相关文章:

  • python机器学习——决策树
  • __attribute__((__used__)) 和 __attribute__((__section__(“*“ “*“)))的使用
  • webgoat-(A1)SQL Injection
  • Flink的API分层、架构与组件原理、并行度、任务执行计划
  • Transformer:开源机器学习项目,上千种预训练模型 | 开源日报 No.66
  • Corel VideoStudio 会声会影2024剪辑中间的视频怎么删 剪辑中音乐太长怎么办
  • 数据结构初阶---复杂度的OJ例题
  • Prometheus|云原生|grafana的admin用户密码重置备忘记录
  • [hive]中的字段的数据类型有哪些
  • 第六章 树【数据结构和算法】【精致版】
  • 第九章:Dynamic Symbolic Execution
  • 在搜索引擎中屏蔽csdn
  • Linux开发工具的使用(vim、gcc/g++ 、make/makefile)
  • MySQL(10):创建和管理表
  • Python赋值给另一个变量且不改变原变量
  • PHP进销存ERP系统源码
  • npm i 报错:Cannot read properties of null (reading ‘refs‘)
  • C#学习中关于Visual Studio中ctrl+D快捷键(快速复制当前行)失效的解决办法
  • 银河E8,吉利版Model 3:5米大车身、45寸大屏、首批8295座舱芯
  • 技术分享 | 被测项目需求你理解到位了么?
  • [MRCTF2020]你传你呢1
  • 一些对程序员有用的网站
  • 小程序使用echarts(超详细教程)
  • js控制输入框中的光标位置
  • Openssl生成证书-nginx使用ssl
  • Go语言实现数据结构栈和队列
  • 【vscode】Window11环境下vscode使用Fira Code字体【教程】
  • Sandcastle生成文档
  • P1368 【模板】最小表示法
  • 【Hive】内部表(Managed Table)和外部表(External Table)相关知识点