【发布时间】:2019-12-04 12:21:31
【问题描述】:
我想创建一个 Vue 插件,其中包含一个以编程方式呈现 Vue 组件的函数。该组件依赖于 Vuetify。如果我在该组件中使用 vanilla HTML/CSS,一切正常,但在其中使用与 Vuetify 相关的东西(例如 a )不起作用。我假设我没有正确地将 vuetify 本身注入到组件中。
在我的自定义组件中,我尝试单独导入每个 Vuetify 组件,但没有成功。我也尝试使用以下语法创建组件:new Vue({vuetify}),但也没有成功。
import MyCustomComponent from '@/components/MyCustomComponent'
import vuetify from '@/plugins/vuetify';
export default {
install(Vue, options) {
function renderMyCustomComponent() {
const CustomComponent= Vue.extend(MyCustomComponent)
Vue.use(vuetify)
let instance = new CustomComponent()
instance.$mount()
document.body.appendChild(instance.$el)
}
Vue.prototype.$renderMyComponent = renderMyCustomComponent
}
}
错误消息表明,vuetify(或至少它的一些属性)在我的组件中不可用
[Vue warn]: Error in getter for watcher "isDark": "TypeError: Cannot read property 'dark' of undefined"
提示/编辑:我使用的是 Vuetify 2.0。将 Vuetify 注入应用程序的方式发生了一些变化。这是我的 vuetify 插件文件的代码:
import Vue from 'vue';
import Vuetify from 'vuetify';
import 'vuetify/dist/vuetify.min.css';
import de from 'vuetify/es5/locale/de';
Vue.use(Vuetify)
export default new Vuetify({
theme: {
themes: {
light: {
primary: '#3f51b5',
secondary: '#b0bec5',
accent: '#8c9eff',
error: '#b71c1c'
},
},
},
});
【问题讨论】:
-
能否提供
'@/plugins/vuetify'的代码? -
刚刚编辑了我的帖子。顺便提一句。我忘了提到我正在使用 Vuetify 2.0.0
标签: vue.js plugins vuetify.js