How to make a pulldown menu that acts on a selected element?


How do I:


To me this sounds like such a trivial and useful thing, e.g. from a pulldown menu.

A little more detail

Assume I’m making an editor of some kind (think todo-list or something). The GUI has the concept of a “selected” element. (In our real case it is the currently visible bootstrap nav-tab), and I want to have pull-down menus with menu-items that perform different operations on the selected element.

Assuming I have the id of the “selected” component, getting a reference to the MyComponent that has a complexOperation() method corresponding to the id is surprisingly difficult.

Perhaps that is because I’m not doing this “the Vue way”.

I see these ways to accomplish complexOperationOnSelectedMyComponent():

  • use refs – seems messy and ugly
  • refactor the complexOperation() out of MyComponent and into a new MyData, so the business logic on the data is used by oth App.vue and MyComponent.vue. Now the parent is changing data and therefore props – sounds vue-ish. But that leads to lots of boilerplate since every operation in every component now has two versions. I’m not a fan of boilerplate and duplication…
  • use vuex? I think I’m not there yet…
  • Use an “event bus” Vue instance and $ emit events from parent to child. Seems overkill. And is messy and has boilerplate.

Am I missing something? Isn’t this pretty standard stuff?


For simplicity, we’ll say that there is a template:

<template>   <div id="app">     <div v-for="elem in mydata" :key="" @click="setSelected(elem)">       <MyComponent :value="elem"/>     </div>     <button @click="complexOperationOnSelectedComponent">         Complex operation on Selected Component     </button>   </div> </template> 

and a data structure where the first one is initially selected:

data() {   return {     mydata: [       { id: 0, foo: "bar", selected: true },       { id: 1, foo: "baz", selected: false },       { id: 2, foo: "world", selected: false }     ]   }; } 

(Complete codesandbox)

So there is a “Complex operation on Selected Component” button. But what should I put in the complexOperationOnSelectedComponent method?

The codesandbox above also has equivalent buttons inside each MyComponent. They simply calls a complexOperation() method in the MyComponent definition.

I’m thinking what whether the button happens to be inside or outside the component is a minor detail. Get a reference to the MyComponent for the selected id and call selectedComponent.complexOperation() in the menu item’s @click handler.

In our real scenario, the user selects the “component” by clicking on a nav-bar, (not on the MyComponent instance), so what we have is a id (mydata[n].id or 0, 1 or 2 above).

Using ref-s

What I could do was put ref="components" in the <MyComponents> definition. Because it is in a v-for loop, this.$ refs.components will then be an array of MyComponents. Find the one with the right id and use it.

Because there is no guarantee about the order of in this.$ refs.components I’d have to search the array for the selectedMyComponentID every time, but hey…

Is this really the best solution?

How to deactivate pull-down tab list view gesture in Google Chromium/Chrome?

For desktop PC’s, I prefer Firefox. But for mobile, I had a better overall experience with Chrome/Chromium. Much smoother, faster, more responsive, no URL bar that changes it’s content once you tap it, and no crashes. The apology of Firefox in the crash reporter does not help. But Google Chrome/Chromium still has a problem: Opening the tab list sometimes causes it to freeze.

There is a gesture in Chrome/Chromium for Android where pulling down from the URL bar does go into the tab list view. But that can also happen accidentially.

But the tab list view occasionally causes the browser to freeze, which forces me to navigate into App Info and kill the process.

Is there any flag in chrome://flags that can deactivate the touch gesture where pulling down from the URL bar brings me into the list of opened tab?

Could SER get a dump to buffer pull-down menu choices on user pop up to solve?

Much like the new feature Sven implemented that will place question into the clipboard, or send to Goo-Gil to be searched…
Also…why do foreign language characters come out looking so messed up when I (Single) click on a pop-up question?
When I double-click, the result that comes up in G  Search looks OK, on the other hand…
Any help…greatly appreciated..

Could SER get a way to buffer the choices in the Category pull-down menus on target sites?

…because I’d like to translate them and learn the phrases that constitute the various categories in different languages.
If there was a way to save the choices, just so I can enter them into G! translate and make a cheat sheet I print out or have in a file so I can learn them, that would be very useful.
Hope all you guys and girls are having a fun weekend.  :)