[Vuejs]-Modify vue component method

0๐Ÿ‘

โœ…

I found it!

I have to extend the component, in my main i seted:

import PictureInput from "vue-picture-input";

Vue.component('PictureInput', PictureInput);
const newPictureInput = Vue.component('PictureInput').extend({
  methods: {
    preloadImage (source, options) {

      ...code...

      let headers = new Headers()
      headers.append('Accept', 'image/*')
      headers.append(newHeader)
      fetch(source, {
        method: 'GET',
        mode: 'cors',
        headers: headers
      })

     ...code...

    }
  }
});

Vue.component('newPictureInput', newPictureInput);

new Vue({
  router,
  store,
  vuetify,
  render: h => h(App)
}).$mount('#app')

And it worked!

0๐Ÿ‘

You cannot override methods in other build components. You can make a fork of this component, change its method and then build it. Or if this component is a simple project, you can copy its .vue file in you project and use it as a local component.

Leave a comment