JavaScript错误:
[Vuetify] Multiple instances of Vue detected
See https://github.com/vuetifyjs/vuetify/issues/4068
If you're seeing "$attrs is readonly", it's caused by this
consoleError @ vuetify.js:22001
install @ vuetify.js:16239
Vue.use @ vue.esm.js:4751
install @ vuetify.js:17943
Vue.use @ vue.esm.js:4751
(anonymous) @ application.js:22
__webpack_require__ @ bootstrap 0e105d68ff80c96169ef:19
(anonymous) @ bootstrap 0e105d68ff80c96169ef:62
(anonymous) @ bootstrap 0e105d68ff80c96169ef:62
尝试过:
详细信息:
我有一个Rails应用,我想在其中使用Vuetify的<v-navigation-drawer>
创建一个导航抽屉。根据{{3}},我使用$ npm install vuetify --save
安装。然后,为了进行功能检查,我在单个文件组件之一中使用了自己的示例:
模板
<!-- app/javascript/navigation-drawer.vue -->
<template>
<div id="nav-drawer">
<v-navigation-drawer permanent>
<v-toolbar flat>
<v-list>
<v-list-tile>
<v-list-tile-title class="title">
Application
</v-list-tile-title>
</v-list-tile>
</v-list>
</v-toolbar>
<v-divider></v-divider>
<v-list dense class="pt-0">
<v-list-tile
v-for="item in items"
:key="item.title"
@click=""
>
<v-list-tile-action>
<v-icon>{{ item.icon }}</v-icon>
</v-list-tile-action>
<v-list-tile-content>
<v-list-tile-title>{{ item.title }}</v-list-tile-title>
</v-list-tile-content>
</v-list-tile>
</v-list>
</v-navigation-drawer>
</div>
</template>
<script>
export default {
data () {
return {
items: [
{ title: 'Home', icon: 'dashboard' },
{ title: 'About', icon: 'question_answer' }
],
right: null
}
}
}
主要application.js
import TurbolinksAdapter from 'vue-turbolinks'
import Vue from 'vue/dist/vue.esm'
import BootstrapVue from 'bootstrap-vue'
import Vuetify from 'vuetify'
import NavigationDrawer from '../navigation-drawer.vue'
import 'bootstrap/dist/css/bootstrap.css'
import 'bootstrap-vue/dist/bootstrap-vue.css'
Vue.use(TurbolinksAdapter)
Vue.use(BootstrapVue)
Vue.use(Vuetify)
Vue.component('navigation-drawer', NavigationDrawer)
document.addEventListener('turbolinks:load', () => {
const app = new Vue({
el: '[data-behavior="vue"]'
})
})
NPM可视化版本
$ npm list vuetify
barber-ranks@ /path/to/app/barber-ranks
└── vuetify@1.3.11
NPM vue版本
$ npm list vue
barber-ranks@ /path/to/app/barber-ranks
├── vue@2.5.17
└─┬ vue-turbolinks@2.0.3
└── vue@2.5.17
注意,该rails项目同时使用npm
和yarn
来管理节点包。我不确定这是否会造成冲突。
答案 0 :(得分:1)
位于this issue中,您可以解析Vue路径并使Vuetify实例与Vue一起使用。
在您的config > webpack > environment.js
中添加:
const { environment } = require('@rails/webpacker')
const vue = require('./loaders/vue')
environment.loaders.append('vue', vue)
const resolver = {
resolve: {
alias: {
'vue$': 'vue/dist/vue.esm.js'
}
}
}
environment.config.merge(resolver)
module.exports = environment
在javascript> application.js中,您现在可以像这样正确地导入Vue和Vuetify:
import Vue from 'vue'
import Vuetify from 'vuetify'