alessiomaffeis / vue-picture-input

Mobile-friendly picture file input component for Vue.js 2-3 with image preview, drag and drop, EXIF orientation, and more
MIT License
888 stars 156 forks source link

SyntaxError Unexpected token '<' after a refresh #139

Closed JR-Utily closed 3 years ago

JR-Utily commented 3 years ago

Hello ! Your module seems very great, I like the simplicity to use it.

But whenever I had it in my nuxt app, I can't refresh (F5) the page any more.

Here is a really simple page with just the component set:

<template>
  <div>
      <h1 class="title">
Upload Cards
</h1>

<!-- No input yet :) -->

</div>
</template>

<script lang="ts">
import { Component, Vue } from 'vue-property-decorator'

import PictureInput from 'vue-picture-input'

@Component({
  components: {
    PictureInput
  }
})
export default class CardsIndex extends Vue {
}

</script>

It display well first time I access the page, but if I F5 (or if I save the file again in dev mode...) it shows: image

The important frame may be this one: image

I'm still discovering Vue.js and Nuxt at the moment, so maybe it is not related to your module and it is a regular newbie issue :)

kihayu commented 3 years ago

Actually, I have the same problem. I'm using Nuxt 2.14.12 with Vue 2.6.11

fcojavierdomenech commented 3 years ago

Any thoughts on this matter?

I've tried cvaize's solution but didn't work for me. Nuxt 2.14.12 also!

fcojavierdomenech commented 3 years ago

Ummm fixed it wrapping the component into <client-only> tags

JR-Utily commented 3 years ago

so you mean that: https://nuxtjs.org/docs/2.x/features/nuxt-components#the-client-only-component ?

fcojavierdomenech commented 3 years ago

Yep, I fixed it with:

                    <client-only>
                      <vue-picture-input 
                        ref="pictureInput"
                        width="128" 
                        height="98" 
                        margin="16" 
                        accept="image/jpeg,image/png" 
                        size="10" 
                        button-class="btn"
                        :custom-strings="{
                        upload: '<h1>Bummer!</h1>',
                        drag: 'Drag a 😺 GIF or GTFO'
                        }"
                        @change="onImageChange">
                      </vue-picture-input>
                    </client-only>

And also setting the ssr to false on my nuxt.config.js:

// Plugins to run before rendering page (https://go.nuxtjs.dev/config-plugins)
  plugins: [
      '~/plugins/vue-api-query',
      '~/plugins/filters',
      { src: '~/plugins/vue-picture-input', ssr: false }
  ],