The responsive dropdown menu is failing to show the elements within the array

My website has a responsive navbar that updates values based on selected tabs.

https://i.sstatic.net/Fl6tM.png

Now, I'm trying to replicate the same functionality in mobile view by using a select menu instead of a navbar.

https://i.sstatic.net/JGrHC.png

However, the value is not changing when I select different options. What am I missing? Thank you!

CodePen

Here's the code snippet:

<template>
  <div>
     <div class="sm:hidden">
      <label for="tabs" class="sr-only">Select a tab</label>
      <select id="tabs" name="tabs" class="block w-full focus:ring-indigo-500 focus:border-indigo-500 border-gray-300 rounded-md">
        <option v-for="tab in tabs" :key="tab.name" :selected="tab.current">{{ tab.name }}</option>
      </select>
        <div >
    <div v-for="tab in tabs" @click="changeTab(tab)"  :key="tab.name" :href="tab.href" class="px-12" :class="[tab.current || 'hidden']">
      {{ tab.id }} - {{ tab.name }} - {{  tab.href }} - {{ tab.title }} - {{tab.imageSrc}}
    </div>
  </div>
    </div>
 
    <div class="hidden sm:block">
     <nav class="flex space-x-4 " aria-label="Tabs" >
        <a v-for="tab in tabs" @click="changeTab(tab)"  :key="tab.name" :href="tab.href" :class="[tab.current ? 'bg-purple-700 text-white' : 'text-purple-700 hover:text-gray-700', 'px-12 py-2 font-medium text-sm rounded-full font-bold text-lg']" >
          {{ tab.name }}
        </a>
      </nav>
    </div>
     <div class="hidden sm:block">
    <div v-for="tab in tabs" @click="changeTab(tab)"  :key="tab.name" :href="tab.href" class="px-12" :class="[tab.current || 'hidden']">
      {{ tab.id }} - {{ tab.name }} - {{  tab.href }} - {{ tab.title }} - {{tab.imageSrc}}
    </div>
  </div>
  </div>
</template>

<script lang="ts">
import { ref } from 'vue'
export default {
  setup() {
    const tabs = ref([
      { id: 1 , title: 'test title one', imageSrc:'/programs/test1.png' , content: '', name: 'LOREM', href: '#test1', current: true },
      { id: 2 , title: 'test title two',  imageSrc:'/programs/test2.png', content: '', name: 'IPSUM', href: '#test2', current: false },
      { id: 3 , title: 'test title three', imageSrc:'/programs/test3.png', content: '', name: 'PDF', href: '#test3', current: false },
      { id: 4 , title: 'test title three', imageSrc:'/programs/test3.png', content: '', name: 'PDF', href: '#test3', current: false },
      { id: 5 , title: 'test title three', imageSrc:'/programs/test3.png', content: '', name: 'PDF', href: '#test3', current: false },
      { id: 6 , title: 'test title three', imageSrc:'/programs/test3.png', content: '', name: 'PDF', href: '#test3', current: false },
      
    ])
    
    const  changeTab = (selectedTab) => {
      tabs.value.map(t => {
        t.id === selectedTab.id ? t.current = true : t.current = false
      });
    }
    
    return { tabs, changeTab }
    
  },
    computed: {
    img() {
      return `./images/modal/${encodeURIComponent(this.tabs[0].imageSrc)}.png`
    },
  },
}
</script>


<style lang="scss" scoped>
  nav {
    display: flex;
    gap: 20px; 
    background: #E5E5E5; 
    border-radius: 20px;
    width: 100%;
justify-content: space-between;
}
</style>

Answer №1

The <select> element in your code is missing a binding. It's recommended to use either a v-bind directive or at least a change handler to properly update the data.

An example of how your change handler could be implemented:

<select
  @change="updateSelection($event.target.value)"
>
...
</select>

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

What is the reasoning behind using the IIFE pattern on certain straightforward member functions in three.js?

Consider the Object3D base class: rotateOnAxis: function () { // rotate object on axis in object space // axis is assumed to be normalized var q1 = new Quaternion(); return function rotateOnAxis( axis, angle ) { q1.setFromAxisA ...

The method being spied on by Sinon has not been called

Testing the code involves a simple process: it triggers a method based on a certain condition. If the condition is not met, another method from within the first one is triggered as an attribute. app.js: function test (fn, isActivated) { if (isActivat ...

Using nested loops in React to access and manipulate nested objects

I have a collection of objects. I need to extract an array of specific data values like this: [ 'someData1', 'someData2', 'someData3' ] in order to map it in React. I believe I should utilize Object.keys, but I&apo ...

Top tips for utilizing numerous XMLHttpRequests efficiently

I am attempting to retrieve 8 JSON objects from 8 different URLs. I have stored the query string that needs to be modified in an Array, and I am looping through it using a for loop. Below is my code: var index = ["ESL_SC2", "OgamingSC2", "cretetion", "fre ...

Comparison of Arrays Containing Objects

I'm looking for a way to compare arrays of nested objects in Mongoose. In the scenario below, I am seeking results where the name properties match. Is there anyone who can assist me with this? Organisation.find( { $or: [ { "c ...

Passing a list of objects containing lists in MVC3

Is it possible for me to send an array of objects, each containing arrays, from JavaScript to a MVC action result method? Essentially, I have a KeyValuePair with keys as arrays of strings and I need to return a list of these KeyValuePairs. In my code, I ha ...

Passing a JSONArray to a webview using addJavascriptInterface can provide valuable data

Within my Android app assets, I have stored an HTML page that I want to display using a WebView and add parameters to the webpage. To achieve this, I populated all the values in a JSONArray and utilized 'addJavascriptInterface' to incorporate th ...

Looking for jQuery bbq... is the grill fired up yet?

In my exploration of the jQuery bbq plugin, I noticed that there is no reference to document.hash in the code. I believe that the function for retrieving the hash is located at line 1094: function get_fragment( url ) { url = url || location.href; ...

Having Trouble Dividing Routes into Individual Files in Express Version 4.0

I need to redirect routes ending with /api to a file called manager.js, which will then route it to /me. For example, a request to /me should be redirected to /api/me. In Express 3.x, splitting routes into separate files was simple, but I'm facing ch ...

Utilizing JSON Data for Dynamically Displaying Database Objects on a Google Map

After carefully reviewing the information provided in the initial responses and working on implementation, I am updating this question. I am currently utilizing the Google Maps API to incorporate a map into my Ruby on Rails website. Within my markets mode ...

Showcasing Portfolio Work in a User-Friendly Mobile Design

Currently revamping my portfolio website and looking for ways to optimize the display of my personal projects. I have a card-like interface in place that works well on desktop but only shows one project at a time on mobile devices. Seeking solutions to imp ...

Removing duplicate entries from a dropdown menu can be achieved by implementing

As a newcomer to the world of PHP PDO, I've learned that the database connection should be in a separate PHP file. However, after spending an entire day trying different things, I'm still facing issues. I suspect that the duplicate entries are a ...

OpenLayers: Issue with OSM visibility within div

I am facing an issue with loading the map content from OpenStreetMaps into a div within my hybrid mobile app. Here is the code snippet I am using: -JS: .controller('myCtrl', function($scope, $state, $ionicPopup, $cordovaGeolocation, Util) ...

Creating an application for inputting data by utilizing angular material and javascript

I am looking to create an application using Angular Material Design, AngularJS (in HTML), and JavaScript. The application should take input such as name, place, phone number, and email, and once submitted, it should be stored in a table below. You can fin ...

Tips for sending a Postgres Pool or Client over a socket

After deploying my server to Heroku, I encountered an issue with sending a request to my Raspberry Pi for running a scraping function and updating a table in the Heroku Postgres database. The problem seems to be related to the client.query() function not b ...

Does using react useMemo offer better performance compared to using a module-level variable?

I'm in need of hard-coding some data for a react component without any changes, and I want to do it in the most efficient way possible. When I say efficient, I mean fast execution with minimal system resource usage. I have two methods in mind: // Meth ...

What is causing Puppeteer to incorrectly capture this page when attempting to take a screenshot?

Utilizing the Node.JS library puppeteer, this code captures a screenshot of a webpage and saves it as a png image: #!/usr/bin/env node const puppeteer = require("puppeteer"); (async () => { const browser = await puppeteer.launch({args: ['--no- ...

Storybook encounters an undefined error with the Vuex store

Here is a snippet from my main.js file: import './plugins'; import store from './store'; import FileUpload from './components/FileUpload'; export default { install(Vue) { Vue.component('file-upload', ...

Button placed within a jade table cell

I'm struggling to make a button appear in each row of the table. I am new to working with Jade and Node.js, so I can't seem to figure out why it's not showing up. Here is my Jade file: html head body table.table.table(border='1 ...

Having trouble with the $.each function?

Values from the database row units for values salam & salavat are as follows: [these values were inserted using json_encode()] salam: [{"name_units":"salam","price_units":"74,554","checkbox_units":["minibar","mobleman"]},{"name_units":"mokhles","pr ...