[英]Add plugins (Vue.use) after instance mounting (new Vue().$mount())
[英]Add plugin to vu Instance as "Vue.use()" without the root vue js file
我正在从事 Directus 项目。 Directus 是一个用 PHP 和 Vue.js 制作的 Headless CMS。
我想在自定义页面上使用主题或插件,例如 Vuetify。 插件通常是这样调用的:
import Vue from 'vue'; // Something like that
Vue.use(...)
但是我无权访问实例化 Vue 的文件。
你知道我是否可以从子文件项目中添加插件和主题吗? 如何 ?
我预先感谢您对您未来的回应!!
亲切地,
尼古拉斯
是的,您可以在创建 Vue 实例后添加插件。
请参阅以下示例:
<template>
<div>
<button type="button" @click="installPlugin">install plugin</button>
<button type="button" @click="callPlugin">call plugin</button>
</div>
</template>
<script>
export default {
name: 'app',
methods: {
installPlugin() {
this.$root.constructor.use({
install(Vue, options) {
console.log('plugin was installed');
Vue.prototype.$test = () => console.log('plugin was called');
},
});
},
callPlugin() {
this.$test();
},
},
};
</script>
在此示例中,插件已安装并在子组件中调用。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.