Refreshing canvas upon Vue.Js + HTML Range modification

My attempt to reload an image when I change a value is facing some challenges. It seems that my vue.js function is only executing once. The goal is to use Caman.js to apply a 'threshold' and 'sharpen' effect based on user input through a range slider, and display a preview of the changes.

HTML

<div id="app">
...
<canvas id="canvas" style="width: 1024px; border:2px solid #333;"></canvas>
...
<input id="sharpen_control" v-model="sharpen_mod" @change="reloadCanvas()" type="range" min="1" max="200">
                   
<input id="threshold_control" v-model="threshold_mod" @change="reloadCanvas()" type="range" min="1" max="200">
...
</div>

Vue.js

el: '#app',
    data: {
        sharpen_mod: '50',
        threshold_mod: '50'
    },
    mounted() {
       this.loadCanvas()
    },

    methods: {
        loadCanvas(){

            const self = this
            const canvas = document.getElementById('canvas');
            const ctx = canvas.getContext('2d');

            const img = new Image();
            img.crossOrigin = 'anonymous';

            img.onload = function() {
                canvas.width = img.naturalWidth
                canvas.height = img.naturalHeight
                ctx.drawImage(img, 0, 0);
            }

            img.src = 'https://i.ibb.co/SNYCXcf/img.jpg';

        },
        reloadCanvas() {
            this.loadCanvas()
            this.drawCanvas()
        },
        drawCanvas(){
            const self = this
            Caman('#canvas', function() {
                this.sharpen(self.sharpen_mod).contrast(5).clip(30).threshold(self.threshold_mod).render();
            });
        }
    }

Answer №1

Not every change to an element's value triggers the change event, unlike the input event.

The behavior of change can be unreliable:

const displayValue = e => {
  document.getElementById('display-value').innerHTML = e.target.value;
}
<input type="range" onchange="displayValue(event)" />
<div id="display-value" />

Consider using input instead:

const logValue = e => {
  document.getElementById('display-value').innerHTML = e.target.value;
}
<input type="range" oninput="logValue(event)" />
<div id="display-value" />

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

Sharing information between Child and Parent components within a VueJs wizard: seamlessly transmitting data

Currently, I am developing a wizard and currently on the 3rd step of the wizard process. Here is the code snippet for handling this step: if(this.currentstep == 3){ var data = this.$parent.permit_info axios.post('/cust ...

How about this sentence: "Automatically select a radio button after verifying the associated sentence (label)

Having a bit of trouble... I'm looking to automatically click a radio button...but also need to verify the corresponding sentence (label)... eg...() <-radio button <label>What is 1+1?</label><br/> <input type="radio" name="gro ...

Exploring Meteor's FS Collection: A guide to efficiently iterate and access CSV files

In my Meteor application, I have a File System collection of CSVs declared as shown below: Uploads = new FS.Collection("yourFileCollection", { stores: [new FS.Store.FileSystem("yourFileCollection", {path: "~/meteor_uploads"})] }); I am trying to iterate ...

Attempting to create a digital keyboard using Bootstrap with the help of JavaScript

In this interactive feature, there is a simple textbox with a virtual keypad that appears and disappears when the user clicks on the keyboard icon inside the text box: https://i.sstatic.net/fdTkn.png Each letter on the virtual keypad is clickable, allowi ...

When React-select is toggled, it displays the keyboard

While using react-select ^1.2.1, I have come across a strange issue. Whenever I toggle the drop-down in mobile view, the keyboard pops up unexpectedly as shown in this screenshot https://i.stack.imgur.com/mkZDZ.png The component code is as follows: rende ...

What is the proper method for incorporating milliseconds into the createdAt field within Sequelize?

In my Node.js project, I am utilizing the Sequelize ORM to handle record writing in a MySQL database. Each table comes with a default createdAt field that only includes datetime information up to seconds: mysql> SELECT createdAt FROM ticks LIMIT 3; +-- ...

How come lazy loading isn't functioning in my React project?

Check out my project: link. This project includes routers and lazy-loaded components for each page. Here's a brief example of a router component: export const RoutersComponent = () => { return ( <HashRouter basename={'/'}> ...

AngularJS mistakenly deletes the incorrect item when using the indexOf method

For the purpose of honing my skills in AngularJS and Rails, I am currently developing a note-taking application which functions similar to a blog. Terms like post equate to note in this context. The left sidebar (controlled by Sidebar.js) fetches all item ...

Scrolling through four limited list items automatically

Hey there! I am currently working on a design project. You can check it out here. I'm trying to replicate a section from another site, which you can see here. <div class="latest-winners-container"> <h3 class="header">Latest Winners< ...

Triggering an event through a shared messaging service to update the content of a component

I'm looking for a simple example that will help me understand how I can change the message displayed in my component. I want to trigger a confirmation box with *ngIf and once I confirm the change, I want the original message to be replaced with a new ...

The art of handling jQuery promises and interconnected AJAX requests

Is there a better way to handle dependent AJAX calls using promises/deferred in jQuery? Currently, my code looks like this: $.when($.ajax('https://somedomain.com/getuserinfo/results.jsonp', { dataType : 'jsonp', jsonp ...

Enhance D3 Version 6 Stacked Bar Chart with Spacing and Interactive Features

My bar chart lacks the spacing between bars that I intended to achieve, and the interactive tooltip doesn't show up when hovering over the bars. I could use some assistance with this. The purpose is to display the value of a specific color when hoveri ...

The concept of an undefined object without a question mark is frowned upon

Consider the following code snippet: app-config.json { "auth": { "clientId": "acb610688b49", }, "cache": { "cacheLocation": "localStorage" }, "scopes": { "loginRequest": ["openid", "profile", "user.read"] }, "resources": { " ...

Exploring the ancestry of Mongo

I am currently working on constructing a family tree that can have an infinite number of levels for parents and children. I am also interested in finding relationships like brothers, sisters, cousins, and so on. However, I'm facing some confusion when ...

Is it possible to include MetaInfo in layouts for Gridsome?

When using Gridsome, I need to access the MetaInfo of any specific page in the layout component. Below is an example of how I can do this: <h1 class="page-title"> {{ metaInfo.title }} </h1> In the actual page, I define the metaInfo like ...

The content of the string within the .ts file sourced from an external JSON document

I'm feeling a bit disoriented about this topic. Is it feasible to insert a string from an external JSON file into the .ts file? I aim to display the URLs of each item in an IONIC InAppBrowser. For this reason, I intend to generate a variable with a sp ...

In order to display a particular view whose filename is determined by the database, I must develop a function within the controller. - laravel

In my system, there is a default page and 4 models that can be changed. The filename corresponding to each model is stored in the database, which is where I encountered some issues. I am unable to pass the variable that determines the filename to the retur ...

Utilizing Bootstrap's nav-pills component within Vue.js 2 framework

The link to the jsfiddle is located here: https://jsfiddle.net/r6o9h6zm/2/ In my project, I have implemented bootstrap nav pills in vue js 2 to show data based on the selected tab. However, I am encountering an issue where all three rooms are being displa ...

Tips for simulating http.ServerResponse and http.IncomingMessage when using express.static

Testing my own route handlers has always been straightforward, but I recently encountered an issue while trying to test express's static handler. Despite my best efforts, I can't seem to figure out why it's stalling. There must be a callback ...

Store Form Input as JSON Data File

Seeking advice on the optimal method to save submitted form data to a separate file called data.json, for future reference. The form layout is quite basic: <form> <fieldset> <label for="name">Name:</label> &l ...