Switching Icon in Vuetify Navigation Drawer Mini Variant upon Click Event

UPDATE

Here's the solution I discovered:

<v-icon>
  {{ mini ? 'mdi-chevron-right' : 'mdi-chevron-left' }}
</v-icon>

Is it feasible to modify the icon when toggling between navigation drawer variants? The default variant should display the mdi-chevron-left icon, and when transitioning to the mini variant, the icon should switch to mdi-chevron-right. Can this be achieved? I haven't been able to locate any relevant information on this issue.

For a complete functional demo, you can find the code here

HTML:

<div id="app">
  <v-app id="inspire">
    <v-app-bar
      color="primary"
      dense
      dark
    >
      
      <v-btn
          icon
          @click.stop="mini = !mini"
          class="mr-2"
      >
        <v-icon>mdi-chevron-left</v-icon>
      </v-btn>

      <v-toolbar-title>Page title</v-toolbar-title>

    </v-app-bar>
    <v-navigation-drawer
      class="deep-purple accent-4"
      dark
      permanent
      v-model="drawer"
      :mini-variant="mini"
    >
      <v-list>
          <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>
            <v-icon left>mdi-logout</v-icon>
            Logout
          </v-btn>
        </div>
      </template>
      </v-navigation-drawer>
  </v-app>
</div>

JAVASCRIPT:

new Vue({
  el: '#app',
  vuetify: new Vuetify(),
  data () {
    return {
      drawer: null,
      mini: false,
      items: [
        { title: 'Dashboard', icon: 'mdi-view-dashboard' },
        { title: 'Account', icon: 'mdi-account-box' },
        { title: 'Admin', icon: 'mdi-gavel' },
      ],
    }
  },
})

Answer №1

Absolutely! By creating a computed variable called appBarIcon, we can determine whether or not "this.mini" is true or false, and display the appropriate icon based on that.

<v-icon>{{ appBarIcon }}</v-icon>
new Vue({
  el: '#app',
  vuetify: new Vuetify(),
  data () {
    ...
  },
  
  // Implementing a computed variable for the app bar icon
  computed: {
    appBarIcon() {
      return this.mini ? "mdi-chevron-right" : "mdi-chevron-left";
    },
  }

})

Check out a live demo on codesandbox.

https://i.sstatic.net/AvDf0.gif

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Utilizing Bootstrap Plugins with Nuxt.js: A Step-by-Step Guide

"dependencies": { "ant-design-vue": "^1.7.2", "bootstrap": "^4.6.0", "core-js": "^3.8.3", "nuxt": "^2.14.12", "popper.js": "^1.16.1" } ...

Perform a search using indexOf method on JSON.stringify objects

I am attempting to determine whether a specific string exists in the following code: var test1 = '{"packageId":"1","machineId":"1","operationType":"Download"},{"packageId":"2","machineId":"2","operationType":"Download"}'; alert("found: " + test1 ...

What is the reason for the visibility of my API key when utilizing next.js alongside environment variables?

I recently went through the next.js documentation and implemented a custom API key on my now server. However, I encountered an issue where when I execute now dev and navigate to the sources tab, my API key is visible. https://i.stack.imgur.com/kZvo9.jpg ...

When attempting to use focusin/focusout, I encountered the following error: Uncaught TypeError - The property 'addEventListener' cannot be read from null

When attempting to utilize the DOM events focusin/focusout, I encountered an error: Uncaught TypeError: Cannot read property 'addEventListener' of null. The issue seems to be originating from main.js at lines 18 and 40. I am using Chrome as my b ...

comparing multiple values separated by commas with JavaScript

I need validation using a comma-separated value format. Within the illustration, there are two fields: "Saloon Price" (value: 10,10,10,10) and "Saloon Offer Price" (value: 11,11,11,11). The first value must be less than the second. Saloon price Value & ...

Understanding the Event Context of Elements using Browser Development Tools

I'm currently investigating the functionality of the search feature on the React Documentation page: https://reactjs.org/ . It's known that they utilize DocSearch, but I'm interested in understanding the inner workings. At the moment, I&ap ...

"Encountering an issue with Express.json where it fails to parse the

Receiving JSON POST data from an IoT API that includes multipart form-data. Occasionally, an image file may be included but I only want to focus on the JSON part: POST { host: '192.168.78.243:3000', accept: '*/*', 'content-le ...

Using SetTimeout with the TextInput component in a React-Native application

Currently, I am working on creating a SearchBar component for my new Android application using React-Native. As a newcomer to React-Native, I created a function called _changeInput() to handle passing text to a local function. Initially, the text pass wor ...

Understanding the specific purpose and functionality of the "next()" parameter in express.js

As a newcomer to express.js, I have been diving into the documentation to understand its nuances. One particular aspect that caught my attention is the next parameter in express middleware, which supposedly triggers the following middleware function for th ...

Passing props from Vue3 to a component being rendered through RouterView

I'm facing an issue with the following code snippet: <template> <router-view /> </template> <script setup lang="ts"> ... const product: Ref<IProduct|undefined>: ref(); ... </script> The challenge is ...

Create a separate server session specifically for handling an ajax request?

Currently, I am working with a collection of PHP server-side scripts that manage user session state by utilizing PHP sessions extensively for authenticated users. For the client side within a mobile application and using Jquery ajax, I am striving to esta ...

How to upload multiple files using AngularJS and Laravel without using a form tag

I am seeking a solution to upload multiple files without using the form tag, utilizing AngularJS with Laravel 5.2. The code snippet below is functional for uploading a single file but fails when attempting to upload multiple files. Here is the HTML Code: ...

Troubleshooting: JavaScript Bookmarklet Fails to Execute on Certain Websites

Recently, I created a unique bookmarklet that functions flawlessly on some websites, but unfortunately fails to work on others. Interestingly, even when it doesn't work, the script is still added to the bottom of the page; however, only a portion of t ...

Is it possible to create a column break within a CSS multicolumn design?

My text content sprawls over a CSS multicolumn layout with two, three, or four columns, utilizing CSS hyphenation. Sometimes, I want to terminate the text in one column early to allow the next paragraph to begin at the top of the next column. Is there a s ...

Clicking on a row in the Gridview should trigger the expansion or collapse of the Nested

My current issue involves a nested GridView setup like this: <asp:GridView ID="gvParent" runat="server" DataKeyNames="id"> <Columns> <asp:TemplateField> <ItemTemplate> <asp:GridView ID="gv ...

What is the best approach to integrating an idle timeout feature with identityserver4 and aspnet identity for a secure implementation?

Currently, I am developing a login site using IdentityServer4 (server UI) with .NET Identity in .NET Core 2.2 Razor Pages. I have implemented a javascript modal alert that notifies users of an impending idle timeout and redirects them to the logout screen ...

Having trouble with prettyphoto functionality

Seeking assistance as I am struggling to get this working Here is how I have set it up: <script src="js/jquery-1.3.2.min.js" type="text/javascript"></script> <link rel="stylesheet" href="css/prettyPhoto.css" type="text/css" media="screen"/ ...

create a sapper route using JSON data

Beginning with the official Sapper template, I am keen on implementing export default as recommended by eslint: export default function get(_, res) { res.writeHead(200, { 'Content-Type': 'application/json', }); res.end(conte ...

Animating background color change with scroll in React using fade effect

Can someone help me with implementing a fading animation for changing the background color on scroll in React? I have successfully achieved the background change effect, but I'm struggling to incorporate the fading effect. import React from "reac ...

Employing live labels on a Morris Bar Chart

I'm using the Morris Bar Chart to showcase the sales of different products. To enhance user experience, I want to display dynamic labels when hovering over the bars. The data is being fetched through PHP. array('product' => $row['pr ...