Skip to content
้กต้ขๅฏผ่ˆช

Vue โ€‹

vue-pdf โ€‹

vue
<template>
    <div>
        <pdf ref="pdf" v-for="i in numPages" :key="i" :src="url" :page="i"></pdf>
    </div>
</template>

<script>
	import pdf from 'vue-pdf'
	export default {
		components: {
			pdf
		},
		data() {
			return {
				url: "/static/resume.pdf",
				numPages: null, // pdf ๆ€ป้กตๆ•ฐ
			}
		},
		mounted() {
			this.getNumPages()
		},
		methods: {
			// ่ฎก็ฎ—pdf้กต็ ๆ€ปๆ•ฐ
			getNumPages() {
				let loadingTask = pdf.createLoadingTask(this.url)
				loadingTask.promise.then(pdf => {
					this.numPages = pdf.numPages
				}).catch(err => {
					console.error('pdf ๅŠ ่ฝฝๅคฑ่ดฅ', err);
				})
			},
		}
	}
</script>

Released under the MIT License.