[英]How can I make a third party Vue library have access to other third-party Vue plugins being used?
假设我在项目中使用vuex,vue-i18n和Syncfusion ej2-vue-grids。
我的应用程序将有权访问$ store和$ t,但是如果我创建网格并为列定义自定义模板,则在该字段中呈现的组件将无法访问vuex或vue-i18n。
通过设置Vue.prototype.$store = store;
我已经能够解决vuex的Vue.prototype.$store = store;
首次设置Vue应用时。 但是,vue-i18n具有几个其他属性,在原型上进行所有设置都感觉像是黑客。
我假设为Grid列创建组件时Syncfusion必须正在调用Vue.extend
,因此该组件将丢失应用程序中的所有上下文。 这是他们方面的错误,还是我应该做些不同的事情?
编辑这是一个plnkr,其中包含我所看到的行为的示例。
https://plnkr.co/edit/XwVC6yNQaI2vQIUoWfSm?p=preview
首次查看时,“货运”列应为空(因为它无法访问商店),并且在网格下方应是一行!!!!!!!! (因为它可以访问商店)。
如果取消注释index.js
第15行,则!!!!!!的行都 在网格下方,并且货运列的内容应该可见。
We need to pass the store and vue-i18n reference to the template declaration.AS in below code snippet.
<pre>
<code>
tmpl() {
return {
template: {
store,
i18n,
data() {
return {
data: {}
}
},
computed: {
test() {
return this.$store.state.test;
}`enter code here`
},
template: `<div>
<div> Translated text child: {{ $t("message.hello") }}</div>
<span>{{ test }} {{ data.Freight }} {{ test }}</span> </div>`
}
}
}
</code>
</pre>
使用商店使用更新的列模板的Plunker示例: https ://plnkr.co/edit/Sei9F1MEvNyLGseZEzM1?p=preview
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.