增加案例页面的错误处理机制

This commit is contained in:
zhcnyuyang 2025-05-11 13:36:25 +08:00
parent 1288dffb3c
commit 4b82c6b546
2 changed files with 19 additions and 8 deletions

View File

@ -110,6 +110,10 @@ export default {
<style scoped lang="scss">
@import "src/publicstyle.scss";
#bannercontentfill{
}
#passagebanner{
@include media-breakpoint-between(xs, md) {
background-image: url('/ExamplesRes/Examplesbanner_wep.png');

View File

@ -2,21 +2,21 @@
<!--<div class="pageroot" style="background-color: white;">-->
<div v-if="this.error==null" id="examplelist">
<div id="typegrid">
<router-link to="/Examples" style="text-decoration: none;">
<a href="/Examples" style="text-decoration: none;">
<div class="typebar"
:class="{
active: (!$route.query.type || $route.query.type === '')}">
全部
</div>
</router-link>
<router-link v-for="(item, index) in this.types"
:key="index":to="`/Examples?type=${item}`"
</a>
<a v-for="(item, index) in this.types"
:key="index":href="`/Examples?type=${item}`"
style="text-decoration: none;">
<div class="typebar"
:class="{ active: $route.fullPath === `/Examples?type=${item}` }">
{{item}}
</div>
</router-link>
</a>
</div>
<!--列表-->
<div id="listmain">
@ -86,18 +86,25 @@ export default {
this.error=null;
const params = new URLSearchParams(window.location.search);
const type = params.get('type');
let reqarg='/api/examples?fields=id,brandname_cn,projectname_cn&populate=headimage';
console.log('type!',type);
let reqarg='/api/examples?fields=id,brandname_cn,projectname_cn&populate=headimage&sort=createdAt:desc';
if(type){
reqarg='/api/examples?fields=id,brandname_cn,projectname_cn&populate=headimage&filters[example_type]='+type;
console.log('type!',type);
reqarg='/api/examples?fields=id,brandname_cn,projectname_cn&populate=headimage&filters[example_type]='+type+'&sort=createdAt:desc';
}
if (this.$route.name != 'Examples'){
let reqarg='/api/examples?fields=id,brandname_cn,projectname_cn&populate=headimage&pagination[page]=1&pagination[pageSize]=5';
let reqarg='/api/examples?fields=id,brandname_cn,projectname_cn&populate=headimage&pagination[page]=1&pagination[pageSize]=5&sort=createdAt:desc';
}
axios.get(reqarg)
.then(response =>{
const resp = response.data;
if(resp.meta.pagination.pageCount==0){
window.location.href = '/Examples';
console.log('turn');
}
if (resp && Array.isArray(resp.data)) {
this.titles = resp.data;
console.log('reqarg',reqarg);
if(this.titles.length==0){
this.error = "返回的 JSON 对象中不存在 'data' 数组";
}