14

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

Dan
  • 151
  • 1
  • 5
  • Yep, I need to change it's functionality, but I don't know how to – Dan Feb 05 '17 at 13:01
  • Does this answer your question? [How do I extend another VueJS component in a single-file component? (ES6 vue-loader)](https://stackoverflow.com/questions/35964116/how-do-i-extend-another-vuejs-component-in-a-single-file-component-es6-vue-loa) – ChewySalmon Jul 31 '20 at 12:48

2 Answers2

2

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
}
Michael2
  • 860
  • 4
  • 15
0

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

Amit K
  • 117
  • 4