zhibo/Zhibo/admin/test-category-api.js

41 lines
1.2 KiB
JavaScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

// 测试分类API的脚本
// 在浏览器控制台运行此代码来检查API响应
// 方法1直接调用API
fetch('http://localhost:9527/admin/room/category/list', {
method: 'GET',
headers: {
'X-Token': localStorage.getItem('token') || sessionStorage.getItem('token'),
'Content-Type': 'application/json'
}
})
.then(response => response.json())
.then(data => {
console.log('API响应:', data);
if (data.code === 200) {
console.log('分类列表:', data.data);
console.log('分类数量:', data.data ? data.data.length : 0);
if (data.data && data.data.length > 0) {
console.log('启用的分类:', data.data.filter(cat => cat.status === 1));
} else {
console.warn('⚠️ 没有分类数据!请检查数据库');
}
} else {
console.error('❌ API返回错误:', data.msg);
}
})
.catch(error => {
console.error('❌ 请求失败:', error);
});
// 方法2检查Vue组件中的数据
console.log('=== 检查Vue组件数据 ===');
setTimeout(() => {
// 尝试获取当前页面的Vue实例
const vueApp = document.querySelector('#app').__vue__;
if (vueApp) {
console.log('Vue实例存在');
// 可以在这里检查组件的categoryList数据
}
}, 1000);