What is the status of Vue?

As a beginner in JavaScript and Vue, I am experimenting with a progress bar and encountering an issue. When the progress bar reaches 0, the data disappears as intended. However, I want the data to reappear when there is progress without needing to refresh the page. Unfortunately, my current code doesn't allow the data to come back once progress is made. I suspect that I need to implement a function to handle this situation. Here is the snippet of my code:

<template>
  <div id="app" v-show="show">
    <vue-ellipse-progress :progress="progress" colorFill="#955251" :noData="nodata" :size="size" :thickness="10" />
  </div>
</template>

<script>

export default {
  name: 'app',
  props: {
    nodata: Boolean,
  },

  components: {},

  data() {
    return {
      size: 100,
      show: true,
      progress: 50,


    };
  },
  mounted() {
    if(this.progress === 0) this.nodata = true
  },
  methods: {},
};
</script>

I have tried using conditions like

"if(this.progress === Number) this.nodata = false"
. While it worked with
"if(this.progress === 1) this.nodata = false"
, the problem is that the progress bar needs to reach exactly 1 for the data to display again. If the progress jumps to something like 20 instantly, it still won't show any data.

I could manually set conditions for all increments (such as 1, 2, 3, etc.) but I believe there must be a simpler solution.

If anyone can offer some guidance, I would greatly appreciate it :)

Answer №1

Utilizing Vue 2 and the Vue CLI, I created a variety of Single File Components inspired by your initial code. For those who are new to Vue, there are a few key points to consider:

  • In Vue, props serve as a means to transfer data from a parent component to a child component. However, in your code snippet, there is no indication of a parent component passing the nodata prop.
  • My approach involves utilizing both a parent and child component. Instead of using noData, I opted to pass progressProp while converting it into a computed property within my example.
  • Your current implementation involves mutating the nodata prop directly, which is generally discouraged. To address this, consider initializing a local data option and setting it with the prop value. Subsequently, any required mutations should be done on the local data option. In my case, I initialized both progress and progressProp data options accordingly.

The following sections outline the components:

Parent.vue

<template>
  <div class="parent">
    <div class="row">
      <div class="col-md-6">
        <vue-ellipse-progress :progressProp="50" />
      </div>
    </div>
  </div>
</template>

<script>
  import VueEllipseProgress from './VueEllipseProgress'

  export default {
    components: {
      VueEllipseProgress
    }
  }
</script>

VueEllipseProgress.vue

<template>
  <div class="vue-ellipse-progress">
    <vue-ellipse-progress :progress="progress" colorFill="#955251" :noData="noData" :size="size" :thickness="10" />
    <div class="form-group">
      <label for="select-progress">Select Progress Amount</label>
      <select class="form-control" id="select-progress" v-model="progress">
        <option :value="0">0</option>
        <option :value="25">25</option>
        <option :value="50">50</option>
        <option :value="75">75</option>
        <option :value="100">100</option>
      </select>
    </div>
  </div>
</template>

<script>
  export default {
    name: 'VueEllipseProgress',
    props: {
      progressProp: {
        type: Number,
        required: true
      }
    },
    computed: {
      noData() {
        return (this.progress === 0) ? true : false;
      }
    },
    data() {
      return {
        size: 100,
        show: true,
        progress: this.progressProp,
      };
    },
    methods: {},
  };
</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

Stop objects from shifting while easily applying a border

I have a code that adds a red border around elements when you mouseover them and removes it when you mouseout. However, the elements jump around when the border is added because it changes their dimensions. Is there a way to stop this jumping behavior? ...

Displaying Title and Description Dynamically on Markers in Angular Google Maps

I am currently utilizing Angular-google-maps, and here is the HTML code snippet: <ui-gmap-google-map center='mapData.map.center' zoom='mapData.map.zoom' events="mapEvents"> <ui-gmap-markers models="mapData.map.markers ...

Restarting the timer in JavaScript

How can I reset the countdown timer every time a user types into an input field? I tried using clearTimeout but it doesn't seem to work. Can anyone help me with my existing code instead of providing new code? DEMO: http://jsfiddle.net/qySNq/ Html: ...

When a div is covered by an if statement

One of the challenges I am facing is managing a view with multiple projects, some of which are active while others are not. In my function, if a project's deadline has passed, it displays '0' days left on the view, indicating that these are ...

Notifying when a refreshed PHP interactive clock has detected new input

I have created a simple countdown timer in PHP that will continuously update the result to be displayed on the page using JavaScript. I am still deciding whether updating every second could potentially cause any issues. The way the countdown works is by r ...

The dimensions of the div do not match the size of the image

I am struggling to adjust the color of a transparent image within a div using jQuery. I am facing difficulties in keeping the image aligned within the div while changing its color. Can someone provide assistance? My goal is to have the image filled upon a ...

NextJS application failing to display SVG icon in the absence of internet connection

https://i.stack.imgur.com/M9reE.jpg https://i.stack.imgur.com/Yyg4g.jpg Upon inspection of the provided images, it is evident that the src URL points to a location within the nextjs public folder. The issue arises when there is no internet connection - i ...

What is the easiest method to transfer a variable from Express to Vue.js?

Hey there! I'm currently diving into Vue.js and finding it quite challenging compared to using EJS. I'm struggling with passing res.locals.something from my Express server to my Vue frontend. Specifically, I am working with Passport.js for user a ...

Encountering a popup_closed_by_user error while attempting to test Google OAuth within my web application

Currently, I am working on integrating Google login into my web application using AngularJS. Whenever the popup opens up for logging into my Google account or selecting an existing account, I encounter an issue where the popup closes with an error message ...

"VS Code's word wrap feature is beneficial for wrapping long lines of text and code, preventing them from breaking and ensuring they are

text not aligning properly and causing unnecessary line breaks insert image here I attempted to toggle the word wrap feature, installed the Rewrap plugin, and played around with vscode settings ...

Is the @vitejs/plugin-vue dependency necessary for my project?

I'm in the process of transitioning a Vue2 project from Vue-CLI/Webpack to Vite. However, I am unsure about whether or not I need to add @vitejs/plugin-vue as a dev dependency as mentioned in this migration guide. Can you clarify if this plugin is nec ...

What is the proper way to update data in reactjs?

I previously had code that successfully updated interval data in the browser and locale without any issues. class Main extends Component { constructor(props) { super(props); this.state = {data: []} } componentWillMount() { fetch('fi ...

Updating data scope in AngularJS using $http request not functioning properly

I am facing an issue where the $scope.user_free_status is not updating when I set a user free, but works perfectly fine when I unset the parameter. It's strange that I need to reload the page in one case and not the other. The data fetched is stored i ...

Transfer the data-url attribute to the jQuery ajax URL

I am facing an issue with my form which includes a data-attribute holding a URL to an API JSON file: <form class="product" action="#" data-url="dist/scripts/main.js"> [...] </form> My goal is to transfer the URL from the data attribute to ...

Prevent mouse over scrolling for every <select> element on a webpage using JQuery

My code seems to be having some issues. Can you help me figure out what's wrong? <script type="text/javascript" language="javascript"> //trying to disable scrolling on mouse over of <select> elements $(document).ready(function() { ...

Utilizing JodaTime with JavaScript (AngularJS): A Comprehensive Guide

I am utilizing DateTime to create Date objects and sending them as JSON to the UI. How can I work with this in JavaScript (specifically AngularJS) and convert it back and forth? For instance, if I need the user to update the time, I should be able to retr ...

Using the Unsigned Right Shift Operator in PHP (Similar to Java/JavaScript's >>> Operator)

Before marking this as a duplicate, please take a moment to read the information below and review my code * my updated code! The issue I am facing is that I need to implement Java/JavaScript '>>>' (Unsigned Right Shift / Zero-fill Rig ...

Ways to stop React from refreshing the page upon clicking the submit button

Is it possible to prevent a React component from reloading the page when a submit button is pressed? Here is an example of component code: class MyComponent extends React.Component<IEditCampaignStateProps & IEditCampaignDispatchProps, EditCampaignStat ...

Transferring TypeScript modules for browserifying

Recently, I transformed my canvas library from plain JavaScript to TypeScript. I have structured the code using classes, all of which are part of the cnvs module. However, I am facing difficulties in compiling these classes into a single file. My goal is ...

"Troubleshooting: Why isn't the AJAX Live Search displaying any

When I try using the live search page in livesearch.php by typing entries into the input box, I am not seeing any results displayed below it. Below is the HTML code and script in search.php. search.php <!DOCTYPE HTML> <html> <he ...