Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

varovas's avatar

How to change vue.js variable value with jQuery

Hi everyone,

I have this strange issue. I am making form 2 buttons that gives YES and NO options. Here's my html:

<button class="yes" data-id="1">Yes</button>
<button class="no" data-id="0">No</button>
<input class="option-val" type=""hidden" v-model="status">

Here's my jQuery code

$('button').click(function() {
    $('option-val').val($(this).attr("data-id"));
});

Here's vue.js:

<script>
    export default {
    data: function () {
        return {
            status: 1
        }
    },
        mounted() {
            console.log('Component ready.')
        }
    }
</script>

The problem is if I click a NO button, status value doesnt change to 0. It's still equal to 1. Do you guys know, how can I solve this problem?

0 likes
4 replies
jaydeluca's avatar
Level 8

Is there a reason you are using jquery instead of just doing it all with Vue?

<button class="yes" @click="status = 1">Yes</button>
<button class="no" @click="status = 0">No</button>
<input class="option-val" type=""hidden" v-model="status">
3 likes
varovas's avatar

Actually, I was thinking about more complex solutions when you come with simple and perfect. Thanks!

2 likes

Please or to participate in this conversation.