S
S
svk442022-04-21 21:31:06
Vue.js
svk44, 2022-04-21 21:31:06

How to add or remove attribute on click in vue?

the input has a readonly attribute.
I know to use @click="function name". I do not know how to refer to the attribute to change the value. how to change its value on click?

there is something like that

<template>
...
        <td><inputtype="text" :value="`${item.id}`" :readonly="readonly"></td>
        <td><button @click="attr_toggle">Toggle</button></td>
</template>

<script>
...
  data(){
    return{
      readonly: true
    }
  },
  methods:{
    attr_toggle(){
      this.readonly = !this.readonly;
    }
  },
</script>

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
Sergey750il, 2022-04-21
@Sergey750il

set ref and refer to it?

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question