如果没有数据,则不显示任何内容。当数据为空时,任何人都可以帮我打印一条消息“无搜索结果”。我是第一次做一份工作,只有基本的想法..请帮助我解决这个问题?
数据为空时我的json数据是:
{ "status": true, "data": [] }
searchContent = new Vue({
el: "#searchContent",
data: {
vector: {}
}
});
categories = new Vue({
el: '#categories',
data: {
category: 0,
subcategory: 0,
content: false
},
watch: {
subcategory: function(e) {
this.prefetch();
},
category: function(e) {
this.prefetch();
},
},
methods: {
prefetch: function() {
var filter = {};
filter['category'] = this.category;
filter['subcategory'] = this.subcategory;
if (this.content !== false)
this.content.abort()
this.content = $.ajax({
'url': 'filter/',
data: filter,
dataType: "JSON",
type: "POST",
success: function(e) {
window.searchContent.vector = e.data;
console.log(e);
}
})
}
}
})
<div id="searchContent">
<div v-for="row in vector">{{row.bussinessName}}</div>
<div>
答案 0 :(得分:2)
您应该在标记中完全执行此操作。试试这个......
<div id="searchContent">
<div v-for="row in vector">{{row.bussinessName}}</div>
<div v-if="vector.length === 0">No search results</div>
<div>
答案 1 :(得分:0)
成功检查数据长度。
success: function(e) {
if(e.data.length > 0)
window.searchContent.vector = e.data;
else
window.searchContent.vector= 'No search reults'
}