1.v-for和data属性
<li v-for="(item, index) in message" v-on:click="addClassFun(index,$event)" :data-qt_id='item.qt_id' v-bind:class='{selectcolor:index==selectIndex}'>
{{ item.type_name }}
</li>
var app=new Vue({
el:'#app',
data:{
message:{},
selectIndex:0,
qt_id:''
},
methods:{
addClassFun:function(index,e){
this.selectIndex = index;
this.qt_id=e.srcElement.dataset.qt_id;
},
},
created:function(){
fetch(url, {
method: "POST",
headers: {
"Content-Type": "application/x-www-form-urlencoded",
},
mode: "cors",
body: JSON.stringify({
content: "留言内容"
})
}).then((res)=>{
return res.json();
}).then((data)=>{
//return res.json();
console.log(this.message)
this.message=data.data;
})
}
})