将插件添加到 vu 实例为“Vue.use()";没有根 vue js 文件 [英] Add plugin to vu Instance as "Vue.use()" without the root vue js file
问题描述
我正在从事 Directus 项目.Directus 是一个用 PHP 和 Vue.js 制作的 Headless CMS.
我想在自定义页面上使用主题或插件,例如 Vuetify.插件通常这样称呼:
从'vue'导入Vue;//类似的东西Vue.use(...)
但我无权访问实例化 Vue 的文件.
你知道我是否可以从子文件项目中添加插件和主题吗?怎么样?
我提前感谢您未来的回复!!
诚挚的,
尼古拉斯
是的,您可以在创建 Vue 实例后添加插件.
看下面的例子:
<div><button type="button" @click="installPlugin">安装插件</button><button type="button" @click="callPlugin">调用插件</button>
</模板><脚本>导出默认{名称:'应用',方法: {安装插件(){this.$root.constructor.use({安装(Vue,选项){console.log('插件已安装');Vue.prototype.$test = () =>console.log('插件被调用');},});},调用插件(){this.$test();},},};
在这个例子中,插件是在子组件中安装和调用的.
I'm working on a Directus Project. Directus is a Headless CMS made in PHP and Vue.js.
I would like to use a theme or a plugin like Vuetify on a custom page. A plugin is often called like this:
import Vue from 'vue'; // Something like that
Vue.use(...)
But i don't have access to the file where Vue is instantiated.
Do you know if i can add plugins and themes from children files project ? How ?
I thank you by advance for your future responses!!
Cordially,
Nicolas
Yes, you can add plugins after the Vue instance was create.
See the bellow example:
<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>
In this example, the plugin was installed and called in a child component.
这篇关于将插件添加到 vu 实例为“Vue.use()";没有根 vue js 文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!