Using Vue 2 and Vuetify, I am trying to implement the shrink on scroll threshold app bar found on the Vuetify page.
This works if I create a v-container on the main App.vue page as in the example on Vuetify's website, but it does not work when scrolling content located in a separate View being shown via the Vue router. Everything shows up but the app bar does not shrink when I scroll on the content being included by the router. How do I get the app bar to track the scrolling of the separate view?
App.Vue:
<template>
<v-app id="inspire">
...
<v-app-bar
app
color="#43a047"
dark
shrink-on-scroll
prominent
src="https://picsum.photos/1920/1080?random"
fade-img-on-scroll
scroll-target="#main"
scroll-threshold="500"
>
<template v-slot:img="{ props }">
<v-img
v-bind="props"
gradient="to top right, rgba(55,236,186,.7), rgba(25,32,72,.7)"
></v-img>
</template>
<v-app-bar-nav-icon #click="drawer = !drawer"></v-app-bar-nav-icon>
<v-toolbar-title>Grocery Manager</v-toolbar-title>
</v-app-bar>
<v-main style="overflow: auto" id="main">
<router-view></router-view>
</v-main>
</v-app>
</template>
HomeView.vue
<template>
<div class="home pa-6">
<h1>Home</h1>
... Lots of text ...
</div>
</template>
<script lang="ts">
import Vue from "vue";
//import HelloWorld from "../components/HelloWorld.vue";
export default Vue.extend({
name: "Home",
components: {
// Add components here
},
});
</script>
Related
I am currently getting to know the vue framework with vuetify, and I am running into a couple issues here ... I have laid out a simple layout for the main page, but for whatever reason, the buttons do not fill the full height, and the background color is using (by default) the hover color. this is what it looks like:
The Code:
<template>
<v-app>
<v-app-bar app> </v-app-bar>
<v-main>
<router-view />
</v-main>
<v-bottom-navigation app v-model="value">
<v-btn value="cards" to="/cards">
<span>Cards</span>
<v-icon>mdi-cards</v-icon>
</v-btn>
<v-btn value="decks" to="/decks">
<span>Decks</span>
<v-icon>mdi-mail</v-icon>
</v-btn>
</v-bottom-navigation>
</v-app>
</template>
<script>
export default {
name: 'App',
data: () => ({
value: 'cards',
}),
}
</script>
it is quite odd that this is happening as the application will randomly fix itself every once in a while when deleting random lines of code, then when I try to change something on the navigation, it will then break again.
Below is the template of my App.vue.
It employs Vuetify's <v-main> and <v-app-bar> UI architecture.
Now I'm wondering how to achieve inter-component communication between the component that lives inside <v-main> and the component that lives inside <v-app-bar>.
<template>
<v-app>
<v-app-bar app color="primary" dark>
<ReadingSelector
:selectedReading="selectedReading"/>
</v-app-bar>
<v-main>
<router-view></router-view>
</v-main>
</v-app>
</template>
My routes contain a single component:
const routes = [
{ path: '/', component: Controller }
]
What is the most elegant and simple way to proceed architecturally?
Is Vuex the answer or is there a better way?
I'm trying to set both bg-color and also text-white to a simple button, but once background color is set, there's no way I can change text color without creating a class and define the color as !important
<v-btn flat class="bg-pink text-white">
<v-icon color="white">mdi-email</v-icon>
<span>Click</span>
</v-btn>
The following link shows the code result screenshot
Click to check code result
What am I doing wrong?
Try this
<v-btn outlined flat color="primary">
<v-icon dense color="error">mdi-email</v-icon>
<span class="white--text"> Click </span>
</v-btn>
When using vuetify, bootstrap classes would conflict with vuetify classes. So you better choose vuetify classes which are of course different from bootstrap classes. Take a look at vuetify documentation for more.
This can be achieved by using bg-{color} class for background color and text color by using text-{color} class. Here is the full documentation on color pallete.
Demo :
const { createApp } = Vue
const { createVuetify } = Vuetify
const vuetify = createVuetify()
const app = createApp({
}).use(vuetify).mount('#app')
<script src="https://unpkg.com/vue#next/dist/vue.global.js"></script>
<script src="https://unpkg.com/#vuetify/nightly#3.0.0-next-20220611.0/dist/vuetify.js"></script>
<link rel="stylesheet" href="https://unpkg.com/#vuetify/nightly#3.0.0-next-20220611.0/dist/vuetify.css"/>
<link rel="stylesheet" href="https://unpkg.com/#mdi/font#6.x/css/materialdesignicons.min.css"/>
<div id="app">
<v-app id="inspire">
<div class="text-xs-center">
<v-btn class="bg-pink">
<v-icon class="text-white">mdi-email</v-icon>
<span class="text-white">Click</span>
</v-btn>
</div>
</v-app>
</div>
As suggested by Rohìt Jíndal I changed the version to vuetify#3.0.0-beta.3 and the problem was solved. Probably it was one of the many fixes they did.
I am trying to implement vuetify in my project. I am newbie in VueJs & vuetify too.
I am trying to use a toolbar which contains a rounded image on the right corner. But, It is not responsive. When i open developer option and decrease the screen size to that of mobile. The rounded image does not render.
I tried using plain tags but it is actually disrupting the layout.
Here is the code
VuetifyTest.vue:
<template lang="html">
<v-toolbar>
<v-toolbar-side-icon>
<!-- <v-img src="../assets/mad_logo.png" aspect-ratio="1.7"></v-img> -->
</v-toolbar-side-icon>
<v-toolbar-title>Title</v-toolbar-title>
<v-spacer></v-spacer>
<v-toolbar-items class="hidden-sm-and-down">
<v-layout
align-center
justify-space-around
wrap
>
<v-avatar
:tile= false
size="36"
color="grey lighten-4"
>
<img src="../assets/static.jpeg" alt="avatar">
</v-avatar>
</v-layout>
</v-toolbar-items>
</v-toolbar>
</template>
<script lang="js">
export default {
name: 'VuetifyTest',
props: [],
mounted() {
},
data() {
return {
}
},
methods: {
},
computed: {
}
}
</script>
<style scoped >
</style>
This is how it looks like in laptop screen
This is how it looks like in mobile screen
How do i change the code to make it responsive
PS: I also tried reducing the screen size while viewing here in reduced screen size.
Even though it showed like this..
Even though the official documentation have this problem?
How do i make it responsive..
thanks!
You do not have to specify v-layout within the v-toolbar - if you remove the v-layout and replace it with just the v-avatar, it works.. Examples are below:
[CodePen Mirror]
Snippet:
new Vue({ el: "#app" })
<script src="https://unpkg.com/vue/dist/vue.js"></script>
<script src="https://unpkg.com/vuetify/dist/vuetify.min.js"></script>
<link href="https://fonts.googleapis.com/css?family=Roboto:300,400,500,700|Material+Icons" rel="stylesheet" />
<link href="https://unpkg.com/vuetify/dist/vuetify.min.css" rel="stylesheet" />
<div id="app">
<v-app>
<v-toolbar>
<v-toolbar-side-icon>
</v-toolbar-side-icon>
<v-toolbar-title>Title</v-toolbar-title>
<v-spacer></v-spacer>
<v-avatar :tile=false size="36" color="grey lighten-4">
<img src="https://i.pravatar.cc/300?img=3" alt="avatar">
</v-avatar>
</v-toolbar>
</v-app>
</div>
Using bootstrap-vue I have a working example using b-tabs and some other of it's components.
However, on one page (.vue) when I try to wrap the block within a tag the page always renders that card and its contents as 'undefined'
I use the sample from here.
Without the v-card I see:
and with it I see:
The code literally follows the sample referenced in the page above and in my main.ts I have the following
import {Card} from 'bootstrap-vue/es/components'
import { Button } from 'bootstrap-vue/es/components';
import { Collapse } from 'bootstrap-vue/es/components';
import { Alert } from 'bootstrap-vue/es/components';
import { Tabs } from 'bootstrap-vue/es/components';
Vue.use(Tabs);
Vue.use(Alert);
Vue.use(Collapse);
Vue.use(Button);
Vue.use(Card);
new Vue({
router,
store,
components: {
bCard: Card,
bButton: Button,
bCollapse: Collapse,
bAlert: Alert,
bTabs: Tabs,
pagination
},
render: h => h(App)
}).$mount("#app");
Can anyone point me in the right direction even to see how to isolate any underlying problem please?
EXTRA CODE ADDED BELOW
Vue (lang="ts") component which does not display correctly:
<template>
<div class="container-fluid">
<div class="row ml-1">
<h4>Complaint Reference: {{ complaint.ComplaintReference }}</h4>
<div class="col-12"><p>Enter the details of the complaint and click Save</p></div>
<div class="col-12">
<b-alert variant="success"
dismissible
:show="showDismissableAlert"
#dismissed="showDismissableAlert=false">
Your changes have been saved
</b-alert>
</div>
</div>
<div class="row">
<!-- the next line is a separate vue component that uses the same approach and which renders correctly -->
<tabs-view></tabs-view>
<div class="col-md-12">
<b-card no-body> <!-- THIS IS WHAT BREAKS! -->
<b-tabs card>
<b-tab title="Details" active>
<p> in first tab</p>
</b-tab>
<b-tab title="Contact">
<p> in second tab</p>
</b-tab>
<b-tab title="Description">
<p> in third tab</p>
</b-tab>
<b-tab title="Outcome">
<p> in final tab</p>
</b-tab>
</b-tabs>
</b-card> <!-- THIS IS WHAT BREAKS! -->
</div>
</div>
<div class="clearfix"></div>
</div>
</template>
<script lang="ts">
import {Component, Prop, Vue} from "vue-property-decorator";
import {Complaint} from "#/components/complaints/Complaint";
import TabsView from '../shared/Tabs.vue'
#Component({
components: {
tabsView: TabsView
}
})
export default class EditComplaintComponent extends Vue {
complaint: Complaint = new Complaint("");
baseUri: string = "api/Complaints/GetByReference/?id=";
showDismissableAlert: Boolean = false;
}
</script>
<style scoped>
</style>
and then another non-TS vue component consumed on the broken one which works correctly with b-tabs inside b-card
<template>
<div>
<b-card title="Card Title"
img-src="https://lorempixel.com/600/300/food/5/"
img-alt="Image"
img-top
tag="article"
style="max-width: 20rem;"
class="mb-2">
<!--<p class="card-text">-->
<!--Some quick example text to build on the card title and make up the bulk of the card's content.-->
<!--</p>-->
<b-button href="#" variant="primary">Go somewhere</b-button>
<b-card no-body>
<b-tabs card>
<b-tab title="first" active>
<br>I'm the first fading tab
</b-tab>
<b-tab title="second" >
<br>I'm the second tab content
</b-tab>
<b-tab title="disabled" disabled>
<br>Disabled tab!
</b-tab>
</b-tabs >
</b-card>
</b-card>
</div>
</template>
<script>
export default {
components: { }
}
</script>
<style scoped>
</style>
I ran into a similar issue with bootstrap-vue 2.21.2. Ended up being that I had a component that wasn't marked up with #Component. After adding it in all my components went from 'undefined' text to display the proper content. See https://github.com/bootstrap-vue/bootstrap-vue/issues/5985#issuecomment-765558938.
Upgrade to the latest version of BootstrapVue to get around this bug.
I had a parent component missing the #Component decorator (in my case it was App.vue) that was causing the undefined behaviour. Make sure that all components have this decorator applied.