[英]modify vue component method
In my project i have installed vue-picture-input but i need to modify a method in PictureInput.vue:在我的项目中,我已经安装了vue-picture-input ,但我需要修改 PictureInput.vue 中的一个方法:
preloadImage (source, options) {
... code ...
let headers = new Headers()
headers.append('Accept', 'image/*')
fetch(source, {
method: 'GET',
mode: 'cors',
headers: headers
})
...code..
}
I need to add an header in the request How can I extend/override it?我需要在请求中添加 header 如何扩展/覆盖它?
in my main.js I open vue as:在我的 main.js 中,我将 vue 打开为:
new Vue({
router,
store,
vuetify,
render: h => h(App)
}).$mount('#app')
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.
或者如果这个组件是一个简单的项目,你可以将它的.vue 文件复制到你的项目中,并将其用作本地组件。
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!它奏效了!
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.