Is there no way to directly add v-for to a custom component? Why is this part no longer loaded after I add v-for? How can I put the data obtained by ajax here? , please give me some help and advice, I’m very grateful
Vue.component('my-article',{
props:['detail','user'],
template:'<h6>{{detail.title}}</h6>'+
'<table id="phone">'+
'<thead>'+
'<tr>'+
'<td style="width: 150px;">{{detail.department}}</td>'+
'<td style="width: 119px;">{{detail.phone1}}</td>'+
'<td style="width: 121px;">{{detail.phone2}}</td>'+
'</tr>'+
'</thead>'+
'<tbody>'+
'<tr v-for="data in users" :user="data">'+
'<td>{{user.name}}</td>'+
'<td>{{user.details1}}</td>'+
'<td>{{user.details2}}</td>'+
'</tr>'+
'</tbody>'+
'</table>'
});
So that it can only execute the tr section in a loop
let vm = new Vue({
el:"#module-duty",
data:{
article:{
title:"值班单位电话",
department:"单位",
phone1:"内线电话",
phone2:"外线电话"
},
users:""
},
created:function(){
$.ajax({
url:"http://localhost:8080/opseyetem/post/find.do",
type:"post",
dataType:"json",
success:function(result){
if(result.state==0){
vm.users = result.data;
}
},
error:function(){
alert("请求失败");
}
});
}
});
Your props receive details, and you use users. Where did your user come from?
Add a props to the component you defined, such as the cdata attribute, to pass data, and reference the component in the parent component
<childComponent cdata="yourAjaxDATA"><childComponent>, so that the child component can cdata.attr Access the data of your AJAX request
The component defined above directly receives a variable detail. Users is a variable of the parent component and cannot be called directly by the child component.
I feel like your writing is a bit messy. Can one ID bind two vue?