Search
 
SCRIPT & CODE EXAMPLE
 

HTML

nuxt input image base64

<template>
  <div class="container">
    <span class="float-end p-2">
          <nuxt-link :to="`../`" class="btn btn-danger btn-sm " accesskey="b">Orqaga</nuxt-link>
        </span>
    <form method="post" class="form-control mt-4" @submit="submitFiles">
      <div class="mb-3">
        <label for="files" class="form-label">Rasmni tanglang</label>
        <input type="file" id="files" ref="files" v-on:change="handleFilesUpload($event)" class="form-control" accept="image/*" autofocus required/>
      </div>
      <div class="mb-3 text-center">
        <img v-if="url" :src="url" class="img-thumbnail w-25"/>
      </div>
      <div class="form-floating mb-3">
        <input type="number" class="form-control" id="rating" v-model="rating" placeholder="Sana" autocomplete="off" required>
        <label for="rating">Testga berilgan ball</label>
      </div>
      <div class="form-floating mb-3">
        <input type="number" class="form-control" id="time" v-model="time" placeholder="Sana" autocomplete="off" required>
        <label for="time">Test yechish uchun berilgan vaqt (soniyada)</label>
      </div>
      <div class="row ms-1" role="group">
        <button class="btn btn-primary col-8 p-2" type="submit">
          Saqlash
        </button>
        <nuxt-link :to="`/admin/question/`" class="btn btn-secondary col-3 p-2 ms-2">
          Orqaga
        </nuxt-link>
      </div>
    </form>
  </div>
</template>
<script>
// import Swal from 'sweetalert2'
export default {
  middleware: 'isAdmin',
  data() {
    return {
      files       : '',
      success     : false,
      name        : '',
      url         : '',
      answers     : {
        answer1: '',
        answer2: '',
        answer3: '',
        answer4: ''
      },
      money       : '',
      rating      : '',
      status      : '',
      status_id   : '',
      time        : '',
      base64_image: '',
    }
  },
  mounted() {
    this.getStatus()
  },
  methods: {
    async getStatus() {
      const data   = await this.$axios.$get(`user/getStatus`);
      this.status  = data.data
      this.success = true
    },
    submitFiles(e) {
      e.preventDefault();
      let formData = new FormData();
      let file     = this.files[0];
      formData.append('files', file);
      formData.append('name', this.name);
      formData.append('answers', JSON.stringify(this.answers));
      formData.append('money', this.money);
      formData.append('rating', this.rating);
      formData.append('time', this.time);
      formData.append('status_id', this.status_id);
      this.$axios.post('admin/question/imageQuestionCreate',
        formData,
        {
          headers: {
            'Content-Type': 'multipart/form-data'
          }
        }).then((res) => {
        this.$router.push(`/admin/question/view/${res.data.data.id}`)
      }).catch((error) => {
        console.log(error)
        console.log('FAILURE!!');
      })
    },
    handleFilesUpload(e) {
      this.files       = this.$refs.files.files;
      const reader     = new FileReader(),
            file       = this.files[0];
      let rawImg;
      reader.onloadend = () => {
        rawImg            = reader.result;
        this.base64_image = rawImg;
        this.url          = rawImg;
      }
      reader.readAsDataURL(file);
    },

  }
}
</script>
Comment

PREVIOUS NEXT
Code Example
Html :: laravel old request html div add style 
Html :: load pdf html 
Html :: send html file express 
Html :: fa fa pencil edit icon 
Html :: ion-datetime change event 
Html :: How do you require 8-digit password in an input 
Html :: stop bubbling 
Html :: bootstrap radio 
Html :: tailwind display inline block 
Html :: html if en change to ltr 
Html :: <meta name="viewport" content="width=device-width, initial-scale=1.0" 
Html :: html redirect 
Html :: how to create html dropdown 
Html :: html5 video player 
Html :: html close window button 
Html :: facebook seo meta tags 
Html :: how inside a word or sentence in circle border in html 
Html :: display subtitles with audio html 
Html :: html dns prefetch 
Html :: side by side tables in bootstrap 
Html :: input limit file type html 
Html :: how to check system is 32 or 64 linux 
Html :: html href phone call 
Html :: html ordered list 
Html :: add delay to button 
Html :: disable overscrolling html 
Html :: abbreviations in html 
Html :: html enctype 
Html :: html bookmark spot 
Html :: font awesome cdn css 
ADD CONTENT
Topic
Content
Source link
Name
7+1 =