Hiding the message

I am in the process of creating a barista small application that consists of three buttons. My goal is to not display any text until one of the three components is clicked by the user. I believe I am very close to achieving this, but I have been unable to find any references to guide me further. Below is my HTML code:

    <div id="app">

    <barista-template></barista-template>
</div>


    <!--template for Barista-->
<script type="text/x-template" id="b-template">
    <div>
        <div> one {{order_type}} that would be {{order_value}}</div>
        <button v-on:click="choose('Drip')">Drip</button>
        <button v-on:click="choose('Frenchpress')">French Press</button>
        <button v-on:click="choose('Aeropress')">Aeropress</button>
    </div>
</script>
</body>
</html>

And here is my Javascript:

Vue.component("barista-template",{
    template: "#b-template",
    data: function () {
        return{
            user_order:"",
            computer:"",
            outcome:"",
            order_type:"",
            order_value: "",    
        }
    },
    methods: {
        choose: function (order_type) {
            this.order_type = order_type;

            if (this.user_order == "drip") {
                if (this.order_value == "drip") this.order_value = $10;

            }
            if (this.user_order == "frenchpress") {
                // if (this.computerMove == "frenchpress") this.outcome ="French press";

            }
            if (this.user_order == "Aeropress") {
                if (this.computerMove == "Aeropress") this.outcome ="Aeropress";

            }

        }
    }

});

new Vue ({
    el:"#app",
    data:function () {
        return{
            showing:false
        }
    }
}); 

Answer №1

To achieve this, I recommend using a computed property, although it can also be done inline like this:

<div v-if="order_type !== ''"> one {{order_type}} that would be {{order_value}}</div>

Utilizing computed properties in your code enhances its readability.

Vue.component("barista-template",{
  template: "#b-template",
  data: function () {
    return{
          order_type:"",
          order_value: "",    
      }
  },
  computed: {
    showText () {
      if(this.order_type === '') return '';
      return 'one ' + this.order_type + ' that would be ' + this.order_value
    }
  },
  methods: {
      choose: function (order_type) {
          this.order_type = order_type;

          if (this.order_type == "drip") {
              this.order_value = "$10";

          }
          if (this.order_type == "frenchpress") {
              this.order_value = "$20";
          }
          if (this.order_type == "aeropress") {
              this.order_value = "$30";
          }
      }
  }

});

new Vue ({
  el:"#app",
  data:function () {
      return{
          showing:false
      }
  }
});
<script src="https://cdnjs.cloudflare.com/ajax/libs/vue/2.4.4/vue.js"></script>
<div id="app">
  <barista-template></barista-template>
</div>

<!--template for Barista-->
<script type="text/x-template" id="b-template">
    <div>
    <div>{{showText}}</div>
    <button v-on:click="choose('drip')">Drip</button>
    <button v-on:click="choose('frenchpress')">French Press</button>
    <button v-on:click="choose('aeropress')">Aeropress</button>
  </div>
</script>

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

Creating a new object and assigning it to an existing reference variable

As a newcomer to Angular, I am facing an issue related to assigning a JSON response from the server to a newly instantiated object. Within my code, I have defined a class called MyClass: export class MyClass { Id: number; } let obj: MyClass; myServi ...

Tips for delaying a node api's execution until a database query no longer returns null

While it may seem like an unnecessary complication, in my current scenario, it is exactly what I require. I am dealing with an API (API-1) that communicates with a third-party service. Instead of directly providing me with a response that I can send back ...

extract keys and values from an array of objects

I would like assistance with removing any objects where the inspectionScheduleQuestionId is null using JS. How can we achieve this? Thank you. #data const data = [ { "id": 0, "inspectionScheduleQuestionId": 1, ...

Experience the mesmerizing motion of a D3.js Bar Chart as it ascends from the bottom to the top. Feel free to

Here is the snippet of code I am working with. Please check the link for the output graph demonstration. [Click here to view the output graph demo][1] (The current animation in the output is from top to bottom) I want to animate the bars from Bottom to ...

Although everything appears to be running smoothly in Express, my request is returning null

I am facing an issue with a router in my code. In the main index.ts file, I have the following line: app.use("/api/tshirts", tshirts) And in tshirts.ts file, I have defined the following routes: router.get("/", tshirtsController.getTShirts) router.get("/ ...

Incorporating a navigation bar into my Jade template

I am working with nodejs, express, and bootstrap for my project. While this may seem like a basic question, I have been unable to find the specific solution I need. My issue lies in the fact that I have a layout.jade file and an index.jade file, with the ...

Locate elements within an array where a specific attribute includes the specified search term

While working with Javascript, I encountered an issue where the function I wrote to retrieve objects from an array was not returning all the data that met the query criteria. In my dataset, which originally contained 1536 objects, there are several jokes ...

Slowly rendering spinner in Google Chrome using jQuery

When I click a button, I want to display a spinner to indicate that the browser is processing actions in the background. Interestingly, the spinner appears immediately after clicking the button on Firefox, but there is an 8-second delay before it shows up ...

Are there any methods to determine the way in which a user has absorbed the content of a post

This particular question sets itself apart from the one found here, as it aims to detect various user behaviors beyond just browser activity. Specifically, I am interested in identifying behaviors such as: Rapidly skimming through an article from start ...

Tips for preserving JSON keys as strings in JavaScript

When executing code similar to the following: The keys in the JSON data will automatically convert from strings to identifier names. I am currently sending this data to a Firebase Realtime Database, but Firebase is flagging the JSON as invalid (since keys ...

When using the JavaScript .sort() method, any undefined value must always be considered as coming before any other value

I am working on sorting an array of objects based on multiple fields, typically around 3-4 fields. Some values within the objects may be undefined, and I need to ensure that these undefined values are considered as "earlier" in the sorting process, wheth ...

The vue function is failing to properly return a value

I am currently utilizing Vue.js and I am facing a challenge retrieving a user's email. I have implemented two separate functions; one to fetch all the products and the other supposed to extract the associated user emails. The trouble I am encounterin ...

Struggling with resizing a webcam feed to fit the dimensions of the iframe container?

I'm facing a challenge embedding a camera feed into a webpage that needs to display manual focus and servo controls. The issue lies in the content scaling within the iframe. Even though the iframe boundary resizes according to the window's width ...

Separate the Array elements and organize them into an object

Check out this code snippet that demonstrates how to divide an array into chunks. If you have a more efficient solution, please share it with me. var numbers = []; for (var i = 0; i < 4500; i++) { numbers.push(i); } var chunks = {}; var start = 0 ...

Styling images using CSS and AngularJS's NG-Repeat functionality

I am currently working on formatting images in AngularJS to display them next to each other in rows of four. However, it seems like when the code is generated from Angular, it is not displaying as expected. Below is a snippet of my HTML: <span ng-repea ...

Attempting to refresh the choices in a dropdown list by sending a request via jQuery leads to specific

I have a Dropdown on my View that looks like this... <div class="editor-field"> @Html.DropDownListFor(model => model.CategoryId, new SelectList(new List<string>(), ""), "Select ...") </div> Within my controller, there is an action ...

What is the technique for arranging the display of a component in React?

Is there a way to dynamically render a component in my react-app at a specific date and time, like 6.00PM on October 27, 2022? I want to release a form for signing up starting from that exact moment. The timestamp information will be stored in my database ...

What is the best way to remove text from a box when a user clicks on it?

After successfully placing G in the selected box upon clicking it, I now want to work on removing it when clicked again. I'm encountering an issue with my current code - can anyone help me identify what's wrong and suggest a solution? Below is ...

What are some creative ways to represent data using different numerical intervals?

Looking to develop a visualization of a .CSV file containing 1.2 million lines, showcasing addresses in the format: source , destination 12.251.512 , 12.623.743 51.734.312 , 23.233.991 6334.6231.123 , 42.532.54453 (utiliz ...

AngularJS - how to dynamically delete a directive from an element

Looking for a way to dynamically add or remove directives from compiled and linked elements? I have a page with numerous inputs and want to disable all of them if a specific flag is set. The conventional method using jQuery's element.prop('disabl ...