I get reference from here : https://vuetifyjs.com/en/getting-started/quick-start
I run vue create my-app, vue add vuetify and npm run serve
My App.vue like this :
<template>
<v-app>
<v-app-bar app>
<v-toolbar-title class="headline text-uppercase">
<span>Vuetify</span>
<span class="font-weight-light">MATERIAL DESIGN</span>
</v-toolbar-title>
<v-spacer></v-spacer>
<v-btn
v-for="link in links"
:key="link"
text
rounded
class="my-2"
:to="'/'+link"
>
{{ link }}
</v-btn>
<v-spacer></v-spacer>
<v-btn
text
href="https://github.com/vuetifyjs/vuetify/releases/latest"
target="_blank"
>
<span class="mr-2">Latest Release</span>
</v-btn>
</v-app-bar>
<v-content>
<HelloWorld/>
</v-content>
</v-app>
</template>
<script>
import HelloWorld from './components/HelloWorld';
export default {
name: 'App',
components: {
HelloWorld,
},
data: () => ({
links: [
'home',
'about',
'contact',
]
}),
};
</script>
My router.js like this :
import Vue from 'vue'
import Router from 'vue-router'
import Home from './views/Home.vue'
Vue.use(Router)
export default new Router({
mode: 'history',
base: process.env.BASE_URL,
routes: [
{
path: '/',
name: 'home',
component: Home
},
{
path: '/about',
name: 'about',
component: () => import('./views/About.vue')
},
{
path: '/contact',
name: 'contact',
component: () => import('./views/Contact.vue')
}
]
})
My Home.vue like this :
<template>
<HelloWorld />
</template>
<script>
import HelloWorld from '../components/HelloWorld';
export default {
components: {
HelloWorld,
},
};
</script>
My HelloWorld.vue like this :
<template>
<v-container>
<v-layout
text-center
wrap
>
<v-flex xs12>
<v-img
:src="require('../assets/logo.svg')"
class="my-3"
contain
height="200"
></v-img>
</v-flex>
<v-flex mb-4>
<h1 class="display-2 font-weight-bold mb-3">
Welcome to Vuetify ss
</h1>
<p class="subheading font-weight-regular">
For help and collaboration with other Vuetify developers,
<br>please join our online
</p>
</v-flex>
</v-layout>
</v-container>
</template>
<script>
export default {
data: () => ({
}),
};
</script>
My About.vue like this :
<template>
<div class="about">
<h1>This is an about page</h1>
</div>
</template>
My Contact.vue like this :
<template>
<div class="contact">
<h1>This is an contact page</h1>
</div>
</template>
I want when content is displayed based on the selected menu. For example when the user selects the about menu, it displays content from the about menu. I try like that. The url changes, but the content does not change. How do I solve this problem?
Update :
I try like this :
<v-btn
v-for="link in links"
:key="link"
text
rounded
class="my-2"
:to="{name: 'about'}">
{{ link }}
</v-btn>
But it's the same
You have no <router-view></router-view> component anywhere in your code. This particular component is responsible for rendering any content in the provided route.
Check for the right example here: https://codesandbox.io/s/qx3orn736q
Related
I try to create routes with vue router. The App.js code looks
JS
require("./bootstrap");
import Swal from "sweetalert2";
import VueI18n from 'vue-i18n'
import VueRouter from 'vue-router'
import Vuetify from "vuetify";
import es from "vuetify/es5/locale/es";
import en from "vuetify/es5/locale/en";
import "#mdi/font/css/materialdesignicons.css";
import ContadorComponent from "./components/ContenedorComponent.vue";
import GatewayComponent from "./components/GatewayComponent.vue";
const routes = [{
path: '/contador',
component: ContadorComponent
},
{
path: '/gateway',
component: GatewayComponent
}
]
window.Vue = require("vue");
Vue.use(Vuetify, VueRouter, VueI18n, Swal);
Vue.component(
"drawer-component",
require("./components/DrawerComponent.vue").default,
/* methods: {
changeLocale (lang) {
this.$vuetify.lang.current = lang
},
},*/
);
export default new Vuetify({
icons: {
iconfont: "mdi"
},
lang: {
locales: {
es,
en
},
current: "es"
}
});
const router = new VueRouter({
routes
})
new Vue({
vuetify: new Vuetify(),
router,
}).$mount("#app");
VUE (Vuetify)
<template>
<v-app id="app">
<v-navigation-drawer v-model="drawer" app permanent expand-on-hover>
<v-list dense>
<v-list-item link>
<v-list-item-action>
<v-icon>mdi-home</v-icon>
</v-list-item-action>
<v-list-item-content>
<v-list-item-title>Principal</v-list-item-title>
</v-list-item-content>
</v-list-item>
<v-list-group prepend-icon="mdi-directions-fork">
<template v-slot:activator>
<v-list-item-title>Gateways</v-list-item-title>
</template>
<v-list-item link>
<v-list-item-icon>
<v-icon>mdi-format-list-bulleted</v-icon>
</v-list-item-icon>
<v-list-item-title>Listado</v-list-item-title>
</v-list-item>
</v-list-group>
<v-list-group prepend-icon="mdi-speedometer">
<template v-slot:activator>
<v-list-item-title>Contadores</v-list-item-title>
</template>
<v-list-item link>
<v-list-item-icon>
<v-icon>mdi-format-list-bulleted</v-icon>
</v-list-item-icon>
<v-list-item-title>Listado</v-list-item-title>
</v-list-item>
</v-list-group>
</v-list>
</v-navigation-drawer>
<v-app-bar app elevate-on-scroll dark>
<v-toolbar-title class="d-sm-flex">LoRaWAN</v-toolbar-title>
<v-divider class="mx-4 d-sm-flex" inset vertical></v-divider>
<v-toolbar-items class="d-sm-flex">
<v-col class="d-flex" cols="3" sm="6">
<v-select :items="items" label="Instalaciones" dense outlined></v-select>
</v-col>
<v-col class="d-flex" cols="3" sm="6">
<v-select :items="items" label="Agrupaciones" dense outlined></v-select>
</v-col>
</v-toolbar-items>
<v-spacer></v-spacer>
<v-menu open-on-hover right bottom>
<template v-slot:activator="{ on }">
<v-btn icon v-on="on">
<v-icon>mdi-account-circle</v-icon>
</v-btn>
</template>
<v-list>
<v-list-item link>
<v-list-item-title>
<v-icon>mdi-exit-run</v-icon>Salir
</v-list-item-title>
</v-list-item>
</v-list>
</v-menu>
</v-app-bar>
<v-content>
<v-container class="fill-height" fluid>
<v-row align="center" justify="center">
<router-link to="/contador">Go to Contadores</router-link>|
<router-link to="/gateway">Go to Gateway</router-link>
</v-row>
</v-container>
<router-view></router-view>
</v-content>
<v-footer dark app>
<span class="white--text">{{ new Date().getFullYear() }}</span>
<span class="white--text text-right">Versión 2.0</span>
</v-footer>
</v-app>
</template>
<script>
export default {
props: {
source: String
},
data: () => ({
items: ["Foo", "Bar", "Fizz", "Buzz"],
drawer: null
})
};
</script>
The problem: Returns Unknown custom element: router-link I import VueRouter so i don´t know what´s fails. Anybody see the error?
Vue.use argument is {Object | Function} plugin.
You are trying to install multiple Vue plugins at once.
Instead of:
Vue.use(Vuetify, VueRouter, VueI18n, Swal);
Do:
Vue.use(Vuetify);
Vue.use(VueRouter);
Vue.use(VueI18n);
Vue.use(Swal);
my v-navigation-drawer takes up the entire row, so the content goes underneath the drawer. I was trying to research online but didn't find anything about it. I am very new to Vuetify. Please help. If you look at the screenshot the Dashboard must be next to drawer but it goes underneath. I have two components Navbar and Drawer. I render them inside of my App.vue. I attached the code below.
App.vue
<template>
<v-app>
<navbar/>
<drawer/>
<v-content>
<h1>Dashboard</h1>
</v-content>
</v-app>
</template>
<script>
import Drawer from './components/Drawer';
import Navbar from './components/Navbar';
export default {
name: 'App',
components: {
Drawer,
Navbar,
},
data: () => ({
}),
method:() => ({})
};
</script>
<style>
</style>
Navbar.vue
<template>
<div>
<nav>
<v-toolbar class="cyan lighten-1" dark prominent height="65">
<v-toolbar-title class="text-uppercase gray--text">
<span class="font-weight-light">Stock</span>
<span>Dashboard</span>
</v-toolbar-title>
<v-spacer></v-spacer>
<v-btn text color="black">
<span>Log Out</span>
<v-icon right>exit_to_app</v-icon>
</v-btn>
</v-toolbar>
</nav>
</div>
</template>
<script>
export default {
data(){
return {
}
}
}
</script>
<style>
</style>
Drawer.vue
<template>
<v-navigation-drawer id="app-drawer" class="cyan lighten-1" dark permanent>
<v-list>
<v-list-tile avatar>
<v-list-tile-avatar color="white">
<v-img :src="require('../assets/bull.svg')" height="70" contain class="cyan darken-5"></v-img>
</v-list-tile-avatar>
</v-list-tile>
<v-list-item
v-for="item in items"
:key="item.title"
link
>
<v-list-item-icon>
<v-icon>{{ item.icon }}</v-icon>
</v-list-item-icon>
<v-list-item-content>
<v-list-item-title>{{ item.title }}</v-list-item-title>
</v-list-item-content>
</v-list-item>
</v-list>
<template v-slot:append>
<div class="pa-2">
<v-btn block>Logout</v-btn>
</div>
</template>
</v-navigation-drawer>
</template>
<script>
export default {
data () {
return {
items: [
{ title: 'Dashboard', icon: 'dashboard' },
{ title: 'Account', icon: 'account_box' },
{ title: 'Admin', icon: 'gavel' },
],
}
},
}
</script>
<style>
</style>
Use "app" in v-navigation-drawer like so :
<v-navigation-drawer id="app-drawer" class="cyan lighten-1" dark permanent app>
Further take a look at https://vuetifyjs.com/en/components/navigation-drawers API and use v-app-bar instead of v-toolbar for the main toolbar of your page.
I'm building a generic table component on VUE, and pass by props the reference source.
Example:
<drk-table table="users"></drk-table>
After this, I use the Axios to load the data from my server in the mounted() event.
This works fine when I have only one component in my template.
But if I try to reuse the component with different props in a conditional v-if, only the first table its load:
<div v-if="currentPage == 0">
<drk-table table="users"></drk-table>
</div>
<div v-else-if="currentPage == 1">
<drk-table table="admins"></drk-table>
</div>
*(currentPage is a data field)*
However if I do the same with v-show it's works:
<div v-show="currentPage == 0">
<drk-table table="users"></drk-table>
</div>
<div v-show="currentPage == 1">
<drk-table table="admins"></drk-table>
</div>
<template>
<div>
<v-app-bar app clipped-left color="amber">
</v-app-bar>
<v-navigation-drawer v-model="drawer" app clipped color="grey lighten-4">
</v-navigation-drawer>
<v-content>
<v-container fluid fill-height>
<v-layout align-center justify-center>
<v-flex text-xs-center>
<div v-if="currentPage == 0">
<drk-table table="users"></drk-table>
</div>
<div v-else-if="currentPage == 1">
<drk-table table="admins"></drk-table>
</div>
</v-flex>
</v-layout>
</v-container>
</v-content>
<v-footer color="indigo" app>
</v-footer>
</div>
</template>
<script>
export default {
data: () => ({
drawer: false,
itens: [
{ icon: 'contacts', text: 'item0' },
{ icon: 'settings', text: 'item1' },
],
currentPage : 0,
}),
methods:{
goPage(item){
console.log("goint to "+item);
this.currentPage = item;
}
}
};
</script>
The official documentation from VUE says that the v-if will recreate the item every time who the condition turns TRUE.
My doubt about this is why the v-if doesn't work properly when I use the same component with different props?
In this case, I need to change my mounted() event?
I'm using a Vue.js project setup with Nuxt and Vuetify.js.
I'm trying to add FontAwesome icons as v-btns to lead the user to an Instagram page.
Unfortunately when clicking the icon, the browser is directed to http://localhost:3000/https://www.instagram.com/therock/?hl=en instead of just https://www.instagram.com/therock/?hl=en as expected. The Instagram account URL is tacked onto the end of the base URL.
Here's the template portion of the Vue file:
<template>
<v-app>
<v-toolbar app flat color="rgb(249, 249, 249)">
<router-link to="/" class="toolbar-title">
<v-toolbar-title>Chumiest Bucket</v-toolbar-title>
</router-link>
<v-spacer></v-spacer>
<v-toolbar-items class="hidden-sm-and-down">
<v-btn
v-for="(item, index) in items"
:key="index"
:to="item.path"
flat
>{{ item.name }}</v-btn>
<v-btn flat :to="instagram.path">
<font-awesome-icon :icon="instagram.icon"/>
</v-btn>
</v-toolbar-items>
<v-menu class="hidden-md-and-up">
<v-toolbar-side-icon slot="activator"></v-toolbar-side-icon>
<v-list>
<v-list-item v-for="(item, index) in items" :key="index">
<v-btn :to="item.path" flat>{{ item.name }}</v-btn>
</v-list-item>
<v-btn flat :to="instagram.path">
<font-awesome-icon :icon="instagram.icon"/>
</v-btn>
</v-list>
</v-menu>
</v-toolbar>
<v-content style="padding-top: 19px;">
<v-container>
<nuxt />
</v-container>
</v-content>
<v-footer app style="position: absolute;">
<span style="font-size: 8pt;">© 2019 Chumiest Bucket</span>
</v-footer>
</v-app>
</template>
here's the script portion of the Vue file:
<script>
export default {
name: 'app',
data() {
return {
fixed: false,
items: [
{
name: 'About',
path: '/about'
},
{
name: 'Stuff',
path: '/stuff'
}
],
instagram: {
icon: ['fab', 'instagram'],
path: 'https://www.instagram.com/therock/?hl=en'
},
}
}
}
</script>
The "to" prop is used for navigating to pages within your routes. See documentation here. To navigate to external links, Bind the url to href instead.
<a :href="instagram.path">
{{ url }}
</a>
I am working with Vuetify and try to make a web page but the vuetify components stylings are not appeared. Could you guide me. Thank you.
My code below.
<template>
<v-app>
<v-navigation-drawer v-model="sidebar" app>
<v-list>
<v-list-tile v-for="item in menuItems" :key="item.title" :to="item.path" #click>
<v-list-tile-action>
<v-icon>{{ item.icon }}</v-icon>
</v-list-tile-action>
<v-list-tile-content>{{ item.title }}</v-list-tile-content>
</v-list-tile>
</v-list>
</v-navigation-drawer>
<v-toolbar color="indigo" dark fixed app>
<v-toolbar-side-icon #click.stop="drawer = !drawer"></v-toolbar-side-icon>
<v-toolbar-title>
<router-link to="/" tag="span" style="cursor: pointer">{{ appTitle }}</router-link>
</v-toolbar-title>
<v-spacer></v-spacer>
<v-toolbar-items class="hidden-xs-only">
<v-btn flat v-for="item in menuItems" :key="item.title" :to="item.path">
<v-icon left dark>{{ item.icon }}</v-icon>
{{ item.title }}
</v-btn>
</v-toolbar-items>
</v-toolbar>
<v-content>
<router-view/>
</v-content>
</v-app>
</template>
<script>
import Vue from 'vue';
import Vuetify from 'vuetify';
import router from '#/router';
Vue.use(Vuetify);
export default {
data() {
return {
appTitle: 'MyEvents',
sidebar: false,
drawer: null,
menuItems: [
{ title: 'Home', path: '/home', icon: 'home' },
{ title: 'Sign Up', path: '/signup', icon: 'home' },
{ title: 'Sign In', path: '/signin', icon: 'home' }
]
};
}
};
</script>
<style>
expected page display like below.
But the as per code page display appear below.
Here my side navigation does not appear properly.
Are you using vue-cli for the project?
If that, you have to install the plugin vue-cli-plugin-vuetify via vue ui.
Here the link: https://vuetifyjs.com/en/getting-started/quick-start
Greetings!