简体   繁体   English

是否可以从导入它的组件文件内部编辑外部Vue.js插件?

[英]IS there a way to edit External Vue.js plugins from inside the component file that imports it?

For example, I'm using vue-charts.js and imported it into my root component: 例如,我正在使用vue-charts.js并将其导入到我的根组件中:

import VueChartjs from 'vue-chartjs';

Vue.component('bar-chart', {
  extends: VueChartjs.HorizontalBar,
...
})

Now VueChartjs is a wrapper for Charts.js so the component comes with its own template. 现在VueChartjs是一个包装Charts.js所以组件本身自带的模板。 I'd like to be able to edit that template within VueChartjs.HorizontalBar or the component bar-chart that I mounted it onto. 我希望能够在VueChartjs.HorizontalBar或我将其安装到的组件bar-chart编辑该模板。

Is there anyway to do this within this root component? 无论如何,在此根组件中可以执行此操作吗?

You can't edit the template of the vue-chartjs component. 您无法编辑vue-chartjs组件的模板。 Because of the extending, all methods, props etc. will get merged. 由于扩展,所有方法,道具等都将合并。 If some props or methods are duplicated, Vue's merge strategy will use your local ones, instead of the ones in the base class. 如果某些道具或方法重复,Vue的合并策略将使用您本地的道具或方法,而不是基类中的道具或方法。

However Vue has no merge strategy for templates. 但是,Vue没有模板的合并策略。 So you could only completely overwrite the template. 因此,您只能完全覆盖模板。 Check the git repo of vue-chartjs to see the template syntax, as some props and ids are required. 检查vue-chartjs的git repo以查看模板语法,因为需要一些道具和ID。 And then you can replace it in your base component. 然后,您可以将其替换为基本组件。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM