javascript - 如何首先将输入字段设置为只读,然后单击 vuejs 中的按钮使其可编辑?

标签 javascript html vue.js readonly input-field

//这些是我的 2 个 div,我必须首先将其设置为只读,或者默认设置为只读,然后单击编辑按钮,我想删除只读并使其可编辑

 <div>
     <input type="text" 
     placeholder="Example@scio.com" v-model="userDetails.email ">
   </div>

  <div>
   <input type="text"  placeholder="+91 860 420 3001"  
    v-model="userDetails.contactNumber">
</div>

//这是我的图标,单击该图标应执行上述操作!!

<img class="pencil-image" 
src="/static/images/pencil-edit-button@2x.png" 
@click="editProfile">

请帮我找到一个适用于 vuejs 的解决方案

最佳答案

<div id="app">
<input type="text" :readonly="shouldDisable" v-model="text"> <button @click="clicked">Edit</button>
<hr>
<p>The value of input is: {{text}}</p>
</div>

new Vue({
  el: "#app",
  data: {
    text: 'text',
    shouldDisable: true
  },
  methods: {
    clicked() {
        this.shouldDisable = false
    }
  }
})

See it in action

关于javascript - 如何首先将输入字段设置为只读,然后单击 vuejs 中的按钮使其可编辑?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49994420/

相关文章:

vue.js - 如何有条件地禁用 Vue v-for 循环中的按钮

javascript - 在 JavaScript 中强制代码按顺序运行

javascript - JQuery/JavaScript 字符限制计数器和文本突出显示

javascript - 在 CDN 上托管 Javascript/Css 无法在慢速连接上加载

javascript - 函数参数的词法环境是什么?

html - 如何将HTML中的具体内容解析到我的App中

Javascript Canvas 绘制问题

javascript - 导航栏内的文本/ Logo 似乎在滚动时摆动/振动

javascript - vue.js:597 [Vue warn]: 属性或方法 "$t"未定义

javascript - 在 Vuejs 组件中使用 videojs-vr