0👍
You can create a component and make functionality inside this:
Vue.component('custom-input', {
template: '#custom-input',
props: ['item', 'label'],
data: function() {
return {
value: '',
edit_data: false,
}
},
methods: {
editData: function() {
this.edit_data = !this.edit_data;
},
saveData: function() {
console.log('saved')
},
}
});
var vm = new Vue({
el: '#app',
data: {
edit_data: false,
customer: {
name: 'John Doe',
email: 'johndoe@gmail.com',
},
},
})
<script src="https://cdnjs.cloudflare.com/ajax/libs/vue/2.6.10/vue.min.js"></script>
<template id="custom-input">
<div class="customer-email item editable">
<label>{{label}}</label>
<div v-if="!edit_data" @click="editData">{{item}}</div>
<form v-if="edit_data">
<input v-model="item">
<button @click="saveData">Save</button>
</form>
</div>
</template>
<div id="app">
<div>
<custom-input :item="customer.email" :label="'email'"> </custom-input>
<custom-input :item="customer.name" :label="'Name'"> </custom-input>
</div>
</div>
Source:stackexchange.com