gpt4 book ai didi

javascript - 如何使用 vueJS 在内部数组中显示 JSON 数据?

转载 作者:行者123 更新时间:2023-12-03 03:06:44 24 4
gpt4 key购买 nike

我的 vueJS 代码是:

<script>
new Vue({
el: '#feed' ,
data: {
data: [],
},
mounted() {
this.$nextTick(function() {
var self = this;
var id = window.location.href.split('=').pop();
console.log(id);
$.ajax({
url: "https://n2s.herokuapp.com/api/post/get/5",
method: "GET",
dataType: "JSON",
success: function (e) {
if (e.status == 1) {
self.data = e.data;
console.log(e.data)
} else {
console.log('Error occurred');
}
}, error: function(){
console.log('Error occurred');
}
});
});
},
})
</script>

这是我用来显示值的 html 代码

<div class="m-single-article" id="feed">
<p>{{details.bussinessName}}</p> //already printed
<p>{{details.pid}}</p> //already printed
<p>{{details.inventory}}</p> //////NOT PRINTING
<p>{{details.sub_category}}</p> ////// NOT PRINTING
</div>

我能够打印除库存和子类别之外的所有数据。请

该 url 将提供 json 数据:

{"status": true, "data": {"pid": 10, "bussinessName": "Ey technology", "services": "1, 3, 4, 2", "inventory": ["specs", "Eye Testing", "Lens", "Doctors"], "workHr": "Monday :9:00AM to 5:00PM,Thuesday :9:00AM to 5:00PM,Wednesday :9:00AM to 5:00PM,Tuesday : 9:00AM to 5:00PM,Friday :9:00AM to 5:00PM,Saturday :9:00AM to 5:00PM,Sunday :9:00AM to 5:00PM", "description": "Good technology company for software", "category": 1, "sub_category": ["Homeo pathy", "Web development"], "lat": 9.5274336, "lon": 76.8224309, "contactName": "simon", "contactEmail": "simon@gmail.com", "contactOfficeAddress": "korno solutions", "contactNumber": "1236547859", "contactOfficeNumber": "858547896", "state": "Canada", "city": "Oranto", "place": "Orania", "pincode": 895621, "referer": 24, "link": 24, "views": 0, "package": 1, "listing_pic": "default", "website": "www.ey.com"}}

通过尝试此操作,我无法显示库存 [] 和子类别 [] 的值。有人可以帮我解决我的问题吗?

我还获得 1、2、3、4 等服务。有没有办法映射到另一个给出服务名称的 json 数据。 https://n2s.herokuapp.com/api/post/get_all_services/

最佳答案

您需要v-for

new Vue({
el: '#feed' ,
data: {
details: [],
},
mounted() {
this.$nextTick(function() {
var self = this;
var id = window.location.href.split('=').pop()
console.log(id)
$.ajax({
url: "https://n2s.herokuapp.com/api/post/get/5",
method: "GET",
dataType: "JSON",
success: function (e) {
if (e.status == 1) {
self.details = e.data;
console.log(e.data)
}
else
{
console.log('Error occurred');}
}, error: function(){
console.log('Error occurred');
}
});
})
},
})
<script src="https://cdnjs.cloudflare.com/ajax/libs/vue/2.5.3/vue.js"></script>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div class="m-single-article" id="feed">
<p>{{details.bussinessName}}</p>
<p>{{details.pid}}</p>
<p v-for="inv in details.inventory">{{inv}}</p>
<p v-for="sub in details.sub_category">{{sub}}</p>
</div>

关于javascript - 如何使用 vueJS 在内部数组中显示 JSON 数据?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47135404/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com