[英]vuejs : how to use v-model in a v-for and watch
I have a list of debits and credits that I fetch
from a server:我有一个从服务器
fetch
的借方和贷方列表:
const myApp = Vue.createApp({
data(){
return{
debits:[],
credits:[],
//cut
}
},
methods:(
fetch(myUrl,this.myInit)
.then(response => response.json())
.then(data => {
this.credits = data.opes.credits,
this.debits = data.opes.debits
})
I display this in aa template, using input type="text"
as contenteditable doesn't work with vue.js.我在 aa 模板中显示它,使用
input type="text"
作为 contenteditable 不适用于 vue.js。 Each line has an id and a content ( intitule
) and when the content is changed, I want the id and the content to be sent to a methods in the vuejs.app.js file.每行都有一个 id 和一个内容(
intitule
),当内容更改时,我希望将 id和内容发送到 vuejs.app.js 文件中的方法。 (preferably a watch
) so on this gets sent to the server that updates the row with the relevant id with the relevant content. (最好是
watch
)这样就被发送到服务器,该服务器用相关的 id 和相关的内容更新行。 This is the code in the template:这是模板中的代码:
<div v-for="ligne in credits"
:debits="ligne"
:key="ligne.id"
class="ligne_entree"
:id="'ligne_' + ligne.id">
<input type="text" v-model="ligne.intitule" :id="'intitule_' + ligne.id">
</div>
I currently do this:我目前这样做:
watch:{
'debits.intitule': function(value){
console.log(watch, value)
}
}
I get no error messages.我没有收到错误消息。 Nothing happens.
什么都没发生。
try to use @input on @change尝试在@change 上使用@input
<template>
<div v-for="ligne in credits"
:debits="ligne"
:key="ligne.id"
class="ligne_entree"
:id="'ligne_' + ligne.id">
<input type="text" @input="intitudeHandler($event, lingne.id)" v-model="ligne.intitule" :id="'intitule_' + ligne.id">
</div>
</template>
<script>
export default{
methods: {
intitudeHandler(newValue, id){ ...do something... }
}
}
</script>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.