Connect the Vue component to the Vue instance

I am currently working with a Vue component that looks like this:

Vue.component('number-input', {
    props: {},
    template: `<textarea class="handsontableInput subtxt area-custom text-center text-bold" v-model="displayValue" @blur="isInputActive = false" @focus="isInputActive = true"></textarea>`,
    data: function() {
        return {
            isInputActive: false
        }
    },
    computed: {
        displayValue: {
            get: function() {
                if (this.isInputActive) { 
                    return this.value.toString()
                } else { 
                    return this.value.toFixed(0).replace(/(\d)(?=(\d{3})+(?:\.\d+)?$)/g, "$1,")
                }
            },
            set: function(modifiedValue) { 
                let newValue = parseFloat(modifiedValue.replace(/[^\d\.]/g, "")) 
                if (isNaN(newValue)) {
                    newValue = 0
                } 
                this.$emit('input', newValue)
            }
        }
    }
})

In addition, I have the following methods named change on my vue instance:

var content_kalkulasi = new Vue({
el: '#kalkulasi-table',
data: {
    arr: [{id:'',name:'',file:'',satuan: 0,sub: 0}],
    total: 0,
    index_upload: 0
}, 
methods:{
    add(){
        var arr = {}
        arr.id = ''
        arr.name = ''
        arr.file = ''
        arr.satuan = 0
        arr.sub = 0
        this.arr.push(arr)
    },
    change(){
        this.total = 0
        for(var x in this.arr){
            this.total += this.arr[x].satuan * this.arr[x].sub 
        }

        console.log(this.total)
    },

Now, I am trying to trigger the method change from the following HTML code:

<number-input style="" v-model="data.sub" v-on:keyup="change"></number-input> 

However, the v-on:keyup="change" event won't trigger. Can anyone advise me on how to call the method v-on:keyup="change" from within the Vue component? Any assistance would be greatly appreciated.

Answer №1

The reason for this issue is that your component is not triggering the keyup event.

To resolve this, update v-on:keyup="change" to v-on:input="change"

Alternatively, you can add the following code to the textarea within your component: @keyup="$emit('keyup')"

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

iOS devices featuring the scroll function allows for seamless navigation and effortless

Here is the code snippet that I am using: $(document).scroll(function() { thedistance(); }); I would like thedistance() to trigger while a user is scrolling on an iOS device, however, it currently only fires after the scrolling has stopped, rather t ...

In jQuery selectors, providing two variables may not yield any results, yet inputting the same string manually produces the desired output

For instance: let a = "1234"; let b = "line1\\\\.5"; Now, this particular code line: "#" + a + b; Produces the following string "#1234line1\\.5" And when I use it in the select ...

Is it more effective to import an entire library or specific component when incorporating it into Create-React-App?

I have a question about optimizing performance. I understand that every library has its own export method, but for instance, on react-bootstrap's official documentation, it suggests: It is recommended to import individual components like: react-boo ...

What is the most effective way to communicate to my client that attempting to conceal the browser toolbar is an ill-advised decision?

One of my clients has a friend who claims to be conducting 'security testing' and insists that the PHP Zend Framework application I developed for them should implement certain browser-side features: hide the location bar, toolbar, bookmarks, me ...

As time passes, the Azure Service Bus Consumer experiences a decline in performance

My issue involves managing different topics with subscriptions, each tied to a consumer. Over time, I've noticed a decline in the number of messages received. Despite trying to utilize maxconcurrentcalls, it seems to only be effective at the start. My ...

Can you tell me if this falls under a POST or GET request?

I found this code snippet on a coding website. I'm curious, would you classify this as a POST request or a GET request? The only modification I made was changing the action location to direct to a Java servlet instead of PHP. <!DOCTYPE html> &l ...

Changing the height of one Div based on another Div's height

I currently have a display of four divs positioned side by side. I am seeking a solution to ensure that the height of each div remains consistent, and should adjust accordingly if one of them increases in size due to added text content. For reference, ple ...

What is the best way to delete markers from a leaflet map?

I need to remove markers from my map. I am looking to create a function that will specifically clear a marker based on its ID. I am utilizing Leaflet for the map implementation. Here is my function: public clearMarkers(): void { for (var id in this. ...

Node.js Express API returns an error status with an empty array response in a RestFul manner

Currently, I am in the process of developing a RestFull API using Node.JS to validate if a specific license plate is registered in my database (which happens to be MySQL). The endpoint that I have set up for this task is as follows: http://localhost:3009/_ ...

Generating a JSON file using JavaScript amidst the presence of unconventional characters in JSON keys

In my Node Red Function Node, I'm currently facing a challenge of generating a JSON file from JavaScript code. The specific format I need for the JSON file is as follows: [ { "H-Nr.":"1", "Pos.-Nr.":"1" }, { "H-Nr.":"1", ...

Issue with Click event not working on dynamically added button in Angular 8

My goal is to dynamically add and remove product images when a user clicks the add or delete button on the screen. However, I am encountering an issue where the function is not being called when dynamically injecting HTML and binding the click event. Below ...

Using jQuery to restrict the occurrence of Ajax POST requests to once every 10 seconds

I created an interactive wizard using HTML that displays multiple panels. Users can navigate through the panels using a Next button and there is also a Finish button available. Whenever the user clicks on the next button, I have set up a click handler to s ...

Changing Image Size in Real Time

Trying to figure out the best way to handle this situation - I need to call a static image from an API server that requires height and width parameters for generating the image size. My website is CSS dynamic, adapting to different screen sizes including ...

What is the best way to retrieve the js window object within emscripten's EM_JS function?

I'm looking to access the window.location in an EM_JS method in order to call a JavaScript method from C++. My attempted approach was: EM_JS(const char*, getlocation, (), { let location = window.location; let length = lengthBytesUTF8(location ...

Enabling and disabling links in a Bootstrap dropdown menu with dynamic functionality on click

One interesting feature of bootstrap is that it allows users to disable links within its dropdown menu component by simply adding a class="disabled" into the corresponding <li> tag. I am looking to create some Javascript code so that when a user sel ...

What is the best way to secure videos and other static files with authentication in a next.js web application?

My goal is to provide static content, specifically videos, exclusively to authorized visitors. I want to secure routes so that they are only accessible to authenticated users. However, the challenge arises when trying to display a video on a page located i ...

Unable to invoke the 'apply' method on an undefined object when configuring directions for the jQuery Google Maps plugin

I've gone through the steps in a tutorial to create a jquery mobile google map canvas here, and have attempted to set it up. However, I keep encountering this error in my JavaScript console: Uncaught TypeError: Cannot call method 'apply' ...

How to Utilize the Vue Instance With the 'this'

Trying to implement this in my VueJs methods results in an error message: this is undefined It seems like arrow functions may not be suitable as their this does not bind to the expected context. Switching to a regular function still causes the same err ...

Call upon the prototype method of the parent class

"I'm having trouble understanding a piece of my code: //constructor function Widget (options) { }; //return the string Widget.prototype._addEditFormString = function (val) { return "<in ...