vuejs v-for和v-if同时使用报变量未定义

复制代码
[Vue warn]: Property "image" was accessed during render but is not defined on instance. 
    at <App> vue.global.js:1630:17
[Vue warn]: Unhandled error during execution of render function 
    at <App>

Uncaught TypeError: image is undefined

查了下官方文档才找到问题所在

vue3和vue2 v-if和v-for同时使用时渲染优先级变了

vue2中v-for优先级高,同时使用v-if可以直接使用v-for的循环体数据

vue3中v-if优先级高,v-if使用v-for循环体数据时数据还未加载,就报未定义了。

无论时vue2还是3,官方都不建议两者一起使用,建议通过template嵌套

vue3文档:https://cn.vuejs.org/guide/essentials/list.html#v-for-with-v-ifhttps://cn.vuejs.org/guide/essentials/list.html#v-for-with-v-if

vue2文档:风格指南 --- Vue.jsVue.js - The Progressive JavaScript Frameworkhttps://v2.cn.vuejs.org/v2/style-guide/#%E9%81%BF%E5%85%8D-v-if-%E5%92%8C-v-for-%E7%94%A8%E5%9C%A8%E4%B8%80%E8%B5%B7%E5%BF%85%E8%A6%81

相关推荐
2601_958492557 小时前
Optimizing Engagement with Freehead Skate - HTML5 Game - Construct 3
前端·html·html5
茉莉玫瑰花茶7 小时前
工作流的常见模式 [ 1 ]
java·服务器·前端
zhangxingchao8 小时前
AI应用开发六:企业知识库
前端·人工智能·后端
山峰哥8 小时前
SQL慢查询调优实战:从全表扫描到索引覆盖的完整复盘
前端·数据库·sql·性能优化
红尘散仙8 小时前
一个 `#[uniffi::export]`,把 Rust 接进 React Native
前端·后端·rust
moshuying8 小时前
AI Coding 最大的 token 黑洞,可能根本不是 prompt
前端
红尘散仙9 小时前
一行 `#[specta::specta]`,让 Tauri IPC 有类型
前端·后端·rust
lichenyang4539 小时前
HarmonyOS HMRouter 接入记录:从普通 Tab Demo 到路由跳转
前端
木斯佳9 小时前
前端八股文面经大全:腾讯WXG暑期前端一面(2026-05-15)·面经深度解析
前端·面试·笔试