Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to use with vue #5

Open
gjvengelen opened this issue Jan 15, 2023 · 1 comment
Open

How to use with vue #5

gjvengelen opened this issue Jan 15, 2023 · 1 comment

Comments

@gjvengelen
Copy link

gjvengelen commented Jan 15, 2023

Hi,

I want to try to see if I can use your package on my website. But I'm struggling a bit to get it to work with Vue3. So I created a simple component:

template>
    <Pagesection>
        <div id="flipbookApp" class="bg-openpeople-grey min-h-screen"></div>
        <button id="flipbookNext">next</button>
        <button id="flipbookPrev">prev</button>
        <button id="flipbookZoom">zoom</button>
    </Pagesection>
</template>

<script setup>
import { init as flipbook } from 'flipbook-viewer';

const app = document.getElementById('flipbookApp')
const next = document.getElementById('flipbookNext')
const prev = document.getElementById('flipbookPrev')
const zoom = document.getElementById('flipbookZoom')


onMounted(async () => {
    flipbook("/fp.pdf", app, (err, viewer) => {
        if (err) console.error(err);

        console.log('Number of pages: ' + viewer.page_count);
        viewer.on('seen', n => console.log('page number: ' + n));

        next.onclick = () => viewer.flip_forward();
        prev.onclick = () => viewer.flip_back();
        zoom.onclick = () => viewer.zoom();
    });
})
</script>

And I' rendering it on the page with a client-only marker to prevent SSR, but everytime I try to load that component it returns an error:

ReferenceError: self is not defined
    at Object.<anonymous> (/Users/gerard/dev/openpeople-content/node_modules/flipbook-viewer/dist/flipbook-viewer.js:1:209)
    at Module._compile (node:internal/modules/cjs/loader:1119:14)
    at Module._extensions..js (node:internal/modules/cjs/loader:1173:10)
    at Module.load (node:internal/modules/cjs/loader:997:32)
    at Module._load (node:internal/modules/cjs/loader:838:12)
    at ModuleWrap.<anonymous> (node:internal/modules/esm/translators:170:29)
    at ModuleJob.run (node:internal/modules/esm/module_job:193:25)
    at async Promise.all (index 0)
    at async ESMLoader.import (node:internal/modules/esm/loader:528:24)
    at async __instantiateModule__ (file:///Users/gerard/dev/openpeople-content/.nuxt/dist/server/server.mjs:25281:3)

Could you point me in the right direction, probably missing something simple.

@theproductiveprogrammer
Copy link
Owner

Hi - I haven't used Vue so I'm not 100% sure but perhaps it's trying to run on Node rather than the browser and unable to access some browser context? This is only a guess.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants