I tried to pass a selected key to a function and set a value for it. Already Vue data has the key(htxt) and I passed the key on edit button event and get the passed key and tried to set prompt dialog's value to it but it's not working.
<html>
<head>
<title>Vue.js Table Edit</title>
<!-- UIkit CSS -->
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/uikit.min.css" />
<!-- UIkit JS -->
<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/js/uikit.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/js/uikit-icons.min.js"></script>
</head>
<body>
<div id="Edit">
<h3>{{ htxt }}<span uk-icon="icon: pencil" @click="onEdit('htxt')"></span></h3>
<span>{{ stxt }}<span uk-icon="icon: pencil" @click="onEdit('stxt')"></span></span>
</div>
<script src="https://cdn.jsdelivr.net/npm/vue/dist/vue.js"></script>
<script>
var edits = new Vue({
el: '#Edit',
data: {
htxt: 'How to change h3 text?',
stxt: 'How to change span text?'
},
methods:{
onEdit: function(val){
console.log("passed val:",val)
var retVal = prompt("Enter your name : ", "your name here");
this.htxt = retVal;
// I passed key to hold the value in onedit function and
// I tried to set value to that key like this.val = retVal
}
}
})
</script>
</body>
</html>