Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
54 views
in Technique[技术] by (71.8m points)

javascript - How to properly browse an image with Vue-Form-Generator ? (cause it doesnt work for me)

I am a new full-stack developer student and I want to use Vue-Form-Generator to generate a form with input fields and I want to browse an image. All of my fields works except the image browse one. It doesn't displays on my page. I tried a lot of things, but my last hope is someone who could know it.

My Vue.js code :

  <div class="page">
  <h2>Ajout d'un chercheur</h2>
    <div class="form">
    <vue-form-generator :schema="schema" :model="model" :options="formOptions"></vue-form-generator>
    </div>
  </div>
</template>

<script>

export default {
    data () {
    return {
      model: {
        avatar: null,
        prenom: 'Prénom',
        nom: 'Nom',
        url: 'www.son_site.fr'
      },
      schema: {
        fields: [
          {
            type: "image",
            label: "Photo",
            model: "avatar",
            placeholder: "Photographie du chercheur",
            browse: true,
            required: true,
            featured:true,
          },
          {
            type: 'input',
            inputType: 'text',
            label: 'Prénom',
            model: 'prenom',
            placeholder: 'Prénom',
            featured: true,
            required: true
          },
          {
            type: 'input',
            inputType: 'text',
            label: 'Name',
            model: 'nom',
            placeholder: 'Nom',
            featured: true,
            required: true
          },
          {
            type: 'input',
            inputType: 'text',
            label: 'URL / Site Web',
            model: 'url',
            placeholder: 'www.son_site.fr',
            featured: true,
            required: true
          },
          {
            type: 'submit',
            onSubmit(model) {
              console.log(model);
            },
            label: '',
            buttonText: "Ajouter",
            validateBeforeSubmit: true
          },
        ]
      },
      formOptions: {
        validateAfterLoad: true,
        validateAfterChanged: true,
        validateAsync: true
      }
    }
  }
}
    
</script>

What it displays : my page with everything except the image browse

The console error

question from:https://stackoverflow.com/questions/65872010/how-to-properly-browse-an-image-with-vue-form-generator-cause-it-doesnt-work

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

Given the console error you have, looks like you are using the "Core" rather than "Full" version of Vue-Form-Generator.

See the docs here for how to use the full version, which includes all field types. The image field type is not in the core version.

// the "full" way
<script>
  import VueFormGenerator from "vue-form-generator";
  import "vue-form-generator/dist/vfg.css";  // optional full css additions
</script>

// the "core" way
<script>
  import VueFormGenerator from "vue-form-generator/dist/vfg-core.js";
  import "vue-form-generator/dist/vfg-core.css";  // optional core css additions
</script>

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

1.4m articles

1.4m replys

5 comments

56.9k users

...