码农知识堂 - 1000bd
  •   Python
  •   PHP
  •   JS/TS
  •   JAVA
  •   C/C++
  •   C#
  •   GO
  •   Kotlin
  •   Swift
  • Vue使用epubjs电子书


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

    在线电子书转换器

    安装:

    npm i epubjs

    简单封装: 

     src/hooks/

    1. import Epub from "epubjs";
    2. import type { Book, Rendition } from 'epubjs'
    3. import type { BookOptions } from 'epubjs/types/book'
    4. import type { RenditionOptions } from 'epubjs/types/rendition'
    5. export function useEpub() {
    6. let book: Book
    7. let rendition: Rendition
    8. function createBook(urlOrData?: string | ArrayBuffer, options?: BookOptions) {
    9. if(!urlOrData) {
    10. book = Epub(options)
    11. } else {
    12. book = Epub(urlOrData, options)
    13. }
    14. return book
    15. }
    16. function render(element: Element | string, options?: RenditionOptions) {
    17. if(!book) return
    18. if(typeof element === 'string') {
    19. rendition = book.renderTo(element, options)
    20. } else {
    21. rendition = book.renderTo(element, options)
    22. }
    23. return rendition
    24. }
    25. function display() {
    26. if(!rendition) return
    27. return rendition.display()
    28. }
    29. function getBook() {
    30. return book
    31. }
    32. function getRendition() {
    33. return rendition
    34. }
    35. return { createBook, render, display, getBook, getRendition }
    36. }

    使用: 

    1. <script setup lang="ts">
    2. import { useEpub } from '../hooks'
    3. import { onMounted } from 'vue'
    4. const { createBook, render, display, getRendition } = useEpub()
    5. onMounted(() => {
    6. createBook('static/example.epub')
    7. render('epub', { width: '100%', height: '100%' })
    8. display()
    9. })
    10. // 上一页
    11. const pre = async () => {
    12. await getRendition().prev()
    13. }
    14. // 下一页
    15. const next = async () => {
    16. await getRendition().next()
    17. }
    18. script>
    19. <style scoped>
    20. .main {
    21. width: 100%;
    22. height: 100%;
    23. display: flex;
    24. flex-direction: column;
    25. justify-content: center;
    26. align-items: center;
    27. }
    28. .main > #epub {
    29. width: 500px;
    30. height: 500px;
    31. border: 1px dashed red;
    32. box-sizing: border-box;
    33. }
    34. .main .btn {
    35. display: flex;
    36. justify-content: space-between;
    37. margin-top: 5px;
    38. }
    39. .main .btn button {
    40. padding: 7px 15px;
    41. margin-left: 20px;
    42. }
    43. 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

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

  • 相关阅读:
    贝加莱工控机维修主板维修5PC600.SX01-00常见故障排查
    k8s Seata1.5.1
    Patroni for opengauss 9:basebackup
    SpringBoot中使用Servlet和Filter
    Java学习之继承的本质(重要)
    mac制作ssl证书|生成自签名证书,nodejs+express在mac上搭建https+wss(websocket)服务器
    Latex公式导出word,Latex转换MathML使用POI导出公式可编辑的Word文件
    【数据结构】哈希表
    基于springboot+vue网上书城系统53
    elasticdump官方教程
  • 原文地址:https://blog.csdn.net/m0_51431448/article/details/134198341
  • 最新文章
  • 攻防演习之三天拿下官网站群
    数据安全治理学习——前期安全规划和安全管理体系建设
    企业安全 | 企业内一次钓鱼演练准备过程
    内网渗透测试 | Kerberos协议及其部分攻击手法
    0day的产生 | 不懂代码的"代码审计"
    安装scrcpy-client模块av模块异常,环境问题解决方案
    leetcode hot100【LeetCode 279. 完全平方数】java实现
    OpenWrt下安装Mosquitto
    AnatoMask论文汇总
    【AI日记】24.11.01 LangChain、openai api和github copilot
  • 热门文章
  • 十款代码表白小特效 一个比一个浪漫 赶紧收藏起来吧!!!
    奉劝各位学弟学妹们,该打造你的技术影响力了!
    五年了,我在 CSDN 的两个一百万。
    Java俄罗斯方块,老程序员花了一个周末,连接中学年代!
    面试官都震惊,你这网络基础可以啊!
    你真的会用百度吗?我不信 — 那些不为人知的搜索引擎语法
    心情不好的时候,用 Python 画棵樱花树送给自己吧
    通宵一晚做出来的一款类似CS的第一人称射击游戏Demo!原来做游戏也不是很难,连憨憨学妹都学会了!
    13 万字 C 语言从入门到精通保姆级教程2021 年版
    10行代码集2000张美女图,Python爬虫120例,再上征途
Copyright © 2022 侵权请联系2656653265@qq.com    京ICP备2022015340号-1
正则表达式工具 cron表达式工具 密码生成工具

京公网安备 11010502049817号