Answer the question
In order to leave comments, you need to log in
Why is a Vue instance created outside of the main app not seeing Vuetify components?
Hello everybody!
I can't figure out why [Vue warn]: Unknown custom element: <v-dialog> - did you register the component correctly? For recursive components, make sure to provide the "name" option.
Trying to make a plugin using vuetify, plugin code
import Vue from 'vue';
import vuetify from "vuetify";
const dialog = {
name:'askdialog',
vuetify,
data:{
askDialog:false,
dialogTitle:'',
dialogMessage: '',
dialogType:'alert'
},
computed:{
buttons(){
switch (this.dialogType) {
case 'confirm':
return [
{title:'OK', icon:'done', command: 'ok'},
{title:'Отмена', icon:'close', command: 'cancel'},
]
case 'ask':
return [
{title:'Да', icon:'done', command: 'ok'},
{title:'Нет', icon:'close', command: 'cancel'},
]
default:
return [
{title:'OK', icon:'done', command: 'ok'},
]
}
}
},
template:' <v-dialog width="500px" v-model="askDialog">\n' +
' <v-card>\n' +
' <v-card-title class="primary" dense primary-title>\n' +
' {{dialogTitle}}\n' +
' </v-card-title>\n' +
' {{dialogMessage}}\n' +
' <v-toolbar dense>\n' +
' <v-spacer></v-spacer>\n' +
' <v-btn v-for="btn in buttons" @click="$emit(btn.command)">\n' +
' <v-icon>{{btn.icon}}</v-icon>\n' +
' {{btn.title}}\n' +
' </v-btn>\n' +
' </v-toolbar>\n' +
' </v-card>\n' +
' </v-dialog>\n'
}
export default {
install(Vue, el){
this.el = el
this.instance = null
Vue.prototype.$dialog=this
},
_checkInstance(){
if(this.instance===null){
this.instance = new Vue(dialog)
this.instance.$mount('#'+this.el)
}
},
alert(title, message, callback){
this._checkInstance()
this.instance.$data.dialogTitle = title
this.instance.$data.dialogMessage = message
this.instance.$data.dialogType = 'alert'
this.instance.$data.askDialog = true
}
}
import askdialog from "./plugins/askdialog";
Vue.use(askdialog,'ask') // ask - id элемента div, куда будет монтироваться
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question