Dan
Dan

Reputation: 151

Extend vue.js component from third-party library

I'm using component ElDatepicker from element-ui and I want to change it's template and event handler method. I'm trying to do something like this in single file component:

import Vue from 'vue';
import ElDatePicker from 'element-datepicker'
Vue.use(ElDatePicker)
var dpkr = Vue.component('ElDatePicker')
console.log(dpkr)
export default {
    extends: ['ElDatePicker']
}

But it doesn't work. How i can change it?

https://github.com/ElemeFE/element/tree/dev/packages/date-picker - component package

Upvotes: 14

Views: 3259

Answers (2)

Michael2
Michael2

Reputation: 930

Your main problem is that extends should specify a single component and not an array. You should reference the component and not the name.

import Vue from 'vue';
import ElDatePicker from 'element-datepicker'

export default {
  extends: ElDatePicker
}

The repo you posted is from element-ui

Do npm install element-ui

Then:

import { DatePicker } from 'element-ui'
export default {
  // Use mixins for array syntax
  mixins: [DatePicker]
  // OR use extends without array
  extends: DatePicker
}

Upvotes: 2

Amit K
Amit K

Reputation: 137

You have to first install Element UI in your project using npm install element-ui. Then you have to edit your main.ts/main.js file and add

import ElementUI from 'element-ui';
import 'element-ui/lib/theme-chalk/index.css';

Vue.use(ElementUI);

This should solve your problem. For more help, check Element UI

Upvotes: 0

Related Questions