I'm currently working on an app that allows users to choose which type of vuetify
element they want to display on the page. There are 4 options available for selection. My goal is to render the corresponding vuetify
component when a user clicks on their chosen option. For example, if the user selects divider
, a
<v-divider></v-divider>
should appear; for spacer
, a <v-spacer></v-spacer>
; for toolbar
, a <v-toolbar></v-toolbar>
; and for text
, a <v-btn></v-btn>
with text should be displayed. I'm struggling to figure out how to achieve this.
You can view a demo of the code in action on this CodePen link
new Vue({
el: "#app",
data() {
return {
elements: [{
title: "Divider",
value: "divider"
},
{
title: "Spacer",
value: "spacer"
},
{
title: "Toolbar",
value: "toolbar"
},
{
title: "Text",
value: "text"
}
],
selected: []
};
},
methods: {
renderElements() {
console.log(this.selected);
this.selected = [];
}
}
});
<script src="https://cdnjs.cloudflare.com/ajax/libs/vue/2.5.17/vue.js"></script>
<script src="https://cdn.jsdelivr.net/npm/<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="5a2c2f3f2e333c231b2e30232f34329a373b39">[email protected]</a>/dist/vuetify.min.js"></script>
<link href="https://cdn.jsdelivr.net/npm/<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="625152425558454b40556f72797765">[email protected]</a>/dist/vuetify.min.css" rel="stylesheet" />
<div id="app">
<v-app id="inspire">
<v-container>
<v-layout column>
<v-flex v-for="el in elements" :key="el.value">
<v-checkbox :value="el.value" v-model="selected" :label="el.title"></v-checkbox>
</v-flex>
<v-btn @click="renderElements"> Render Dynamic Elements</v-btn>
</v-layout>
</v-container>
</v-app>
</div>
If anyone can provide guidance on this, it would be greatly appreciated.